[llvm-bugs] [Bug 37630] New: [IndVarSimplify] Canonicalize to IV type by extending LIV operand

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 30 10:09:00 PDT 2018


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

            Bug ID: 37630
           Summary: [IndVarSimplify] Canonicalize to IV type by extending
                    LIV operand
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: listmail at philipreames.com
                CC: llvm-bugs at lists.llvm.org

Looking at IR today, we end up with a bunch of patterns of the following form
which fail to get further reduced or optimized.  I'm still chasing where
exactly these come from - my current best guess is a pass ordering problem
between CVP and IndVars which results in us widening without learning overflow
facts - but there's no reason we shouldn't handle this case anyway.

My specific proposal is that we remove the trunc, widen the compare to 64 bits,
and insert a sext of the loop invariant operand.  We can do this when:
1) The trunc does not change range of the input.  Can be checked with SCEVs
range mechanism.
2) The right operand is loop invariant.
3) The comparison is signed. (We can use a zext when unsigned.)
4) The widened type is as cheap as the narrow type.  (See the same check in
IndVarSimplify widening logic.)

I believe this can be added to eliminateIVComparison in
Utils/SimplifyIndVars.cpp naturally.

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @test2(i32 %n) {
entry:
  br label %loop
loop:
  %iv = phi i64 [0, %entry], [%iv.next, %loop]
  %iv.next = add nuw nsw i64 %iv, 1
  %sext = trunc i64 %iv to i32
  %cmp = icmp slt i32 %sext, %n
  br i1 %cmp, label %loop, label %exit
exit:
  ret void
}

-- 
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/20180530/f8b1e669/attachment.html>


More information about the llvm-bugs mailing list