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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to