[llvm-bugs] [Bug 42631] New: Transform (1 << (x+1)) to (2 << x)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 16 03:30:08 PDT 2019


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

            Bug ID: 42631
           Summary: Transform (1 << (x+1)) to (2 << x)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

%a = add nuw i32 %x, 1
%r = shl i32 1, %a
  =>
%r = shl i32 2, %x

Done: 1
Optimization is correct!


int v1(unsigned x) {

    return (2 << x);
}

int v2(unsigned x) {

    return (1 << (x+1));
}

v1:                                     # @v1
        mov     ecx, edi
        mov     eax, 2
        shl     eax, cl
        ret
v2:                                     # @v2
        lea     ecx, [rdi + 1]
        mov     eax, 1
        shl     eax, cl
        ret

Worth to do? Opinions?

-- 
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/20190716/80233883/attachment.html>


More information about the llvm-bugs mailing list