[llvm-bugs] [Bug 32706] New: instcombine transforms arithmetic into xor which can't be analyzed by ScalarEvolution

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 18 18:10:07 PDT 2017


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

            Bug ID: 32706
           Summary: instcombine transforms arithmetic into xor which can't
                    be analyzed by ScalarEvolution
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: efriedma at codeaurora.org
                CC: llvm-bugs at lists.llvm.org

C Testcase:

unsigned a(unsigned x, unsigned y) { return 4*(-1-x+y); }

Resulting IR (clang -O2 -emit-llvm):

define i32 @a(i32 %x, i32 %y) local_unnamed_addr #0 {
entry:
  %sub = xor i32 %x, 1073741823
  %add = add i32 %sub, %y
  %mul = shl i32 %add, 2
  ret i32 %mul
}

Result of passing this IR to opt -analyze -scalar-evolution:

Printing analysis 'Scalar Evolution Analysis' for function 'a':
Classifying expressions for: @a
  %sub = xor i32 %x, 1073741823
  -->  %sub U: full-set S: full-set
  %add = add i32 %sub, %y
  -->  (%y + %sub) U: full-set S: full-set
  %mul = shl i32 %add, 2
  -->  (4 * (%y + %sub)) U: [0,-3) S: [-2147483648,2147483645)
Determining loop execution counts for: @a


SelectionDAG generally manages to figure out the xor is actually a "not", but
ScalarEvolution currently does not.  (This is reduced from a more complicated
testcase where it actually does matter that ScalarEvolution can't analyze it.)

-- 
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/20170419/fa367dcf/attachment.html>


More information about the llvm-bugs mailing list