[LLVMbugs] [Bug 21245] New: InstCombine: (X << C1) / C2 -> X / (C2 >> C1) isn't always possible

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Oct 10 10:58:22 PDT 2014


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

            Bug ID: 21245
           Summary: InstCombine: (X << C1) / C2 -> X / (C2 >> C1) isn't
                    always possible
           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

In InstCombiner::commonIDivTransforms(), we have the following transformation:
// (X << C1) / C2 -> X / (C2 >> C1) if C2 is a multiple of C1.

However, this is not correct if C1 == width(C1) - 1.

Optimization: 775
Pre: C2 % (1<<C1) == 0
%s = shl nsw i4 %X, C1
%r = sdiv %s, C2
  =>
%r = sdiv %X, (C2 / (1 << C1))


ERROR: Mismatch in values of i4 %r

Example:
%X i4 = 15 (0xf)
C1 i4 = 3 (0x3)
C2 i4 = 8 (0x8)
%s i4 = 8 (0x8)
Source value: 1 (0x1)
Target value: 15 (0xf)


This version is correct though:
Name: 775
Pre: C2 % (1<<C1) == 0 && C1 != width(C1)-1
%s = shl nsw %X, C1
%r = sdiv %s, C2
  =>
%r = sdiv %X, C2/(1<<C1)

-- 
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/20141010/518522ac/attachment.html>


More information about the llvm-bugs mailing list