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: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to