[LLVMbugs] [Bug 21255] New: InstCombine: '(x lshr C1) udiv C2 --> x udiv (C2 << C1)' incorrect if C2<<C1 overflows

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Oct 13 02:24:16 PDT 2014


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

            Bug ID: 21255
           Summary: InstCombine: '(x lshr C1) udiv C2 --> x udiv (C2 <<
                    C1)'  incorrect if C2<<C1 overflows
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: nunoplopes at sapo.pt
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following transformation in InstCombiner::visitUDiv() is incorrect if
C2<<C1 overflows (and btw correct otherwise):

; (x lshr C1) udiv C2 --> x udiv (C2 << C1)
%Op0 = lshr %X, C1
%r = udiv %Op0, C2
  =>
%r = udiv %X, (C2 << C1)

Done: 1
ERROR: Domain of definedness of Target is smaller than Source's for i2 %r

Example:
%X i2 = 0x0 (0)
C1 i2 = 0x1 (1)
C2 i2 = 0x2 (2, -2)
%Op0 i2 = 0x0 (0)
Source value: 0x0 (0)
Target value: undef



And bypassing the undef case:

Pre: ((C2 << C1) != 0)
%Op0 = lshr exact %X, C1
%r = udiv %Op0, C2
  =>
%r = udiv %X, (C2 << C1)


ERROR: Mismatch in values of i4 %r

Example:
%X i4 = 0x2 (2)
C1 i4 = 0x1 (1)
C2 i4 = 0x9 (9, -7)
%Op0 i4 = 0x1 (1)
Source value: 0x0 (0)
Target value: 0x1 (1)



And finally we have:

Pre: WillNotOverflowUnsignedShl(C2, C1)
%Op0 = lshr %X, C1
%r = udiv %Op0, C2
  =>
%r = udiv %X, (C2 << C1)

Done
Optimization is correct!

-- 
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/20141013/b102f68d/attachment.html>


More information about the llvm-bugs mailing list