[llvm-commits] [llvm] r155884 - in /llvm/trunk: lib/Transforms/Scalar/LICM.cpp test/Transforms/LICM/speculate.ll

Nick Lewycky nicholas at mxc.ca
Mon Apr 30 21:03:01 PDT 2012


Author: nicholas
Date: Mon Apr 30 23:03:01 2012
New Revision: 155884

URL: http://llvm.org/viewvc/llvm-project?rev=155884&view=rev
Log:
An instruction in a loop is not guaranteed to be executed just because the loop
has no exit blocks. Fixes PR12706!

Modified:
    llvm/trunk/lib/Transforms/Scalar/LICM.cpp
    llvm/trunk/test/Transforms/LICM/speculate.ll

Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=155884&r1=155883&r2=155884&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Mon Apr 30 23:03:01 2012
@@ -618,6 +618,11 @@
     if (!DT->dominates(Inst.getParent(), ExitBlocks[i]))
       return false;
 
+  // As a degenerate case, if the loop is statically infinite then we haven't
+  // proven anything since there are no exit blocks.
+  if (ExitBlocks.empty())
+    return false;
+
   return true;
 }
 

Modified: llvm/trunk/test/Transforms/LICM/speculate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/speculate.ll?rev=155884&r1=155883&r2=155884&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LICM/speculate.ll (original)
+++ llvm/trunk/test/Transforms/LICM/speculate.ll Mon Apr 30 23:03:01 2012
@@ -165,3 +165,25 @@
 for.end:                                          ; preds = %for.inc, %entry
   ret void
 }
+
+; SDiv is unsafe to speculate inside an infinite loop.
+
+define void @unsafe_sdiv_c(i64 %a, i64 %b, i64* %p) {
+entry:
+; CHECK: entry:
+; CHECK-NOT: sdiv
+; CHECK: br label %for.body
+  br label %for.body
+
+for.body:
+  %c = icmp eq i64 %b, 0
+  br i1 %c, label %backedge, label %if.then
+
+if.then:
+  %d = sdiv i64 %a, %b
+  store i64 %d, i64* %p
+  br label %backedge
+
+backedge:
+  br label %for.body
+}





More information about the llvm-commits mailing list