[llvm-bugs] [Bug 31377] New: [ppc] unnecessary zero extension / clear left instruction

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 14 14:09:18 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31377

            Bug ID: 31377
           Summary: [ppc] unnecessary zero extension / clear left
                    instruction
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: PowerPC
          Assignee: unassignedbugs at nondot.org
          Reporter: carrot at google.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Compile the following code with options -m64 -O2 -mvsx -mcpu=power8

typedef unsigned long long uint64;

void foo(unsigned char* p, uint64* pval) {
      uint64 code = *p; 
      if (code < 128) {
        *pval = code;
      }   
}

LLVM generates:

foo:                                    # @foo
.Lfunc_begin0:
# BB#0:                                 # %entry
        lbz 3, 0(3)                // A
        extsb. 3, 3                // B
        bltlr 0
# BB#1:                                 # %if.then
        clrldi   3, 3, 56          // C
        std 3, 0(4)
        blr


Instruction A load a byte from *p and zero extends it, instruction B sign
extends it and set cr accordingly, instruction C clears high bits, the result
should be exactly the result of instruction A.
So if instruction B write the result to a different register, or use cmpli
directly, instruction C can be removed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161214/f4051c9f/attachment-0001.html>


More information about the llvm-bugs mailing list