[llvm-bugs] [Bug 24670] New: Induction variable simplification does not simplify truncates

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 1 18:53:45 PDT 2015


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

            Bug ID: 24670
           Summary: Induction variable simplification does not simplify
                    truncates
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: sanjoy at playingwithpointers.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Currently LLVM does not optimize `%c0` to `i1 true` in the following example:

declare void @use()

define void @f(i32 %len) {
 entry:
  %e = icmp slt i32 0, %len
  br i1 %e, label %loop, label %leave

 loop:
  %idx = phi i64 [ 0, %entry ], [ %idx.inc, %be ]
  %idx.inc = add i64 %idx, 1
  %idx.tr = trunc i64 %idx to i32
  call void @use()
  %c0 = icmp slt i32 %idx.tr, %len
  br i1 %c0, label %be, label %leave

 be:
  %idx.inc.tr = trunc i64 %idx.inc to i32
  call void @use()
  %c1 = icmp slt i32 %idx.inc.tr, %len
  br i1 %c1, label %loop, label %leave

 leave:
  ret void
}


The interesting bit is that SCEV already has all the smarts required to
optimize this check away; and calling `simplifyLoopIVs` optimizes the check as
expected.  -indvars does not get this case because it does not look through
truncates of induction variables, and thus does not try to eliminate `%c0`.

-- 
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/20150902/34924048/attachment.html>


More information about the llvm-bugs mailing list