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

            Bug ID: 41988
           Summary: Missing opt with ctlz and shifts of power of 2
                    constants
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: matthew.arsena...@amd.com
                CC: llvm-bugs@lists.llvm.org

It should be possible to eliminate a ctlz of a shift of a power of 2 by turning
it into an add:

declare i32 @llvm.ctlz.i32(i32, i1)

define i32 @foo(i32 %log2) {
  %div = lshr i32 8387584, %log2
  %ctlz = call i32 @llvm.ctlz.i32(i32 %div, i1 false)
  ret i32 %ctlz
}

define i32 @bar(i32 %log2) {
  %ctlz.const = call i32 @llvm.ctlz.i32(i32 8387584, i1 false)
  %add = add i32 %log2, %ctlz.const
  ret i32 %add
}

define void @test() {
  %foo = call i32 @foo(i32 6)
  store volatile i32 %foo, i32* undef
  %bar = call i32 @bar(i32 6)
  store volatile i32 %bar, i32* undef
  ret void
}

-- 
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