[LLVMbugs] [Bug 21477] New: exact shift right of constant not optimized (instcombine / value tracking)

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 4 09:01:31 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21477

            Bug ID: 21477
           Summary: exact shift right of constant not optimized
                    (instcombine / value tracking)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

[Follow-on from bug 21412.]

An exact shift right guarantees that no set bits are shifted out, so this:

define i32 @exact_shift(i32 %shiftval) {
  %shr = lshr exact i32 1, %shiftval
  ret i32 %shr
}

...should be optimized to:

define i32 @exact_shift(i32 %shiftval) {
  ret i32 1
}

Ie, %shiftval must be zero, or we have undefined behavior / poison.

In the other bug, the shift is followed by division, so the ideal optimization
for:

define i32 @exact_div(i32 %x, i32 %shiftval) {
  %shr = lshr exact i32 1, %shiftval
  %div = udiv i32 %x, %shr
  ret i32 %div
}

...will be:

define i32 @exact_div(i32 %x, i32 %shiftval) {
  ret i32 %x
}

-- 
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/20141104/aed6b487/attachment.html>


More information about the llvm-bugs mailing list