[llvm-commits] [llvm] r139574 - in /llvm/trunk: lib/Transforms/Scalar/IndVarSimplify.cpp test/Transforms/IndVarSimplify/floating-point-iv.ll

Andrew Trick atrick at apple.com
Mon Sep 12 18:59:32 PDT 2011


Author: atrick
Date: Mon Sep 12 20:59:32 2011
New Revision: 139574

URL: http://llvm.org/viewvc/llvm-project?rev=139574&view=rev
Log:
[indvars] Fix bugs in floating point IV range checks noticed by inspection.

Modified:
    llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
    llvm/trunk/test/Transforms/IndVarSimplify/floating-point-iv.ll

Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=139574&r1=139573&r2=139574&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Mon Sep 12 20:59:32 2011
@@ -351,14 +351,14 @@
   // Positive and negative strides have different safety conditions.
   if (IncValue > 0) {
     // If we have a positive stride, we require the init to be less than the
-    // exit value and an equality or less than comparison.
-    if (InitValue >= ExitValue ||
-        NewPred == CmpInst::ICMP_SGT || NewPred == CmpInst::ICMP_SGE)
+    // exit value.
+    if (InitValue >= ExitValue)
       return;
 
     uint32_t Range = uint32_t(ExitValue-InitValue);
-    if (NewPred == CmpInst::ICMP_SLE) {
-      // Normalize SLE -> SLT, check for infinite loop.
+    // Check for infinite loop, either:
+    // while (i <= Exit) or until (i > Exit)
+    if (NewPred == CmpInst::ICMP_SLE || NewPred == CmpInst::ICMP_SGT) {
       if (++Range == 0) return;  // Range overflows.
     }
 
@@ -378,14 +378,14 @@
 
   } else {
     // If we have a negative stride, we require the init to be greater than the
-    // exit value and an equality or greater than comparison.
-    if (InitValue >= ExitValue ||
-        NewPred == CmpInst::ICMP_SLT || NewPred == CmpInst::ICMP_SLE)
+    // exit value.
+    if (InitValue <= ExitValue)
       return;
 
     uint32_t Range = uint32_t(InitValue-ExitValue);
-    if (NewPred == CmpInst::ICMP_SGE) {
-      // Normalize SGE -> SGT, check for infinite loop.
+    // Check for infinite loop, either:
+    // while (i >= Exit) or until (i < Exit)
+    if (NewPred == CmpInst::ICMP_SGE || NewPred == CmpInst::ICMP_SLT) {
       if (++Range == 0) return;  // Range overflows.
     }
 

Modified: llvm/trunk/test/Transforms/IndVarSimplify/floating-point-iv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/floating-point-iv.ll?rev=139574&r1=139573&r2=139574&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/floating-point-iv.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/floating-point-iv.ll Mon Sep 12 20:59:32 2011
@@ -67,7 +67,8 @@
 return:
 	ret void
 ; CHECK: @test4
-; CHECK: fcmp
+; CHECK-NOT: cmp
+; CHECK: br i1 false
 }
 
 ; PR6761
@@ -84,9 +85,8 @@
 
 exit:
   ret void
-  
+
 ; CHECK: @test5
 ; CHECK: icmp eq i32 {{.*}}, 10
 ; CHECK-NEXT: br i1
 }
-





More information about the llvm-commits mailing list