[llvm-commits] [llvm] r74073 - in /llvm/trunk: lib/Analysis/ScalarEvolution.cpp test/Transforms/IndVarSimplify/loop_evaluate7.ll test/Transforms/IndVarSimplify/loop_evaluate8.ll

Dan Gohman gohman at apple.com
Wed Jun 24 07:46:36 PDT 2009


Author: djg
Date: Wed Jun 24 09:46:22 2009
New Revision: 74073

URL: http://llvm.org/viewvc/llvm-project?rev=74073&view=rev
Log:
Simplify [su]max(MAX, n) to MAX. This comes up in loop tripcount
computations in loops with multiple exits.

Adjust the testcase for PR4436 so that the relevant portion isn't
optimized away.

Added:
    llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate8.ll   (contents, props changed)
      - copied, changed from r74072, llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate7.ll
Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp
    llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate7.ll

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=74073&r1=74072&r2=74073&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Jun 24 09:46:22 2009
@@ -1690,10 +1690,14 @@
       LHSC = cast<SCEVConstant>(Ops[0]);
     }
 
-    // If we are left with a constant -inf, strip it off.
+    // If we are left with a constant minimum-int, strip it off.
     if (cast<SCEVConstant>(Ops[0])->getValue()->isMinValue(true)) {
       Ops.erase(Ops.begin());
       --Idx;
+    } else if (cast<SCEVConstant>(Ops[0])->getValue()->isMaxValue(true)) {
+      // If we have an smax with a constant maximum-int, it will always be
+      // maximum-int.
+      return Ops[0];
     }
   }
 
@@ -1777,10 +1781,14 @@
       LHSC = cast<SCEVConstant>(Ops[0]);
     }
 
-    // If we are left with a constant zero, strip it off.
+    // If we are left with a constant minimum-int, strip it off.
     if (cast<SCEVConstant>(Ops[0])->getValue()->isMinValue(false)) {
       Ops.erase(Ops.begin());
       --Idx;
+    } else if (cast<SCEVConstant>(Ops[0])->getValue()->isMaxValue(false)) {
+      // If we have an umax with a constant maximum-int, it will always be
+      // maximum-int.
+      return Ops[0];
     }
   }
 

Modified: llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate7.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate7.ll?rev=74073&r1=74072&r2=74073&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate7.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate7.ll Wed Jun 24 09:46:22 2009
@@ -4,7 +4,7 @@
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
 target triple = "i386-pc-linux-gnu"
 
-define i8* @string_expandtabs() nounwind {
+define i8* @string_expandtabs(i32 %n, i8* %m) nounwind {
 entry:
 	br i1 undef, label %bb33, label %bb1
 
@@ -22,11 +22,11 @@
 
 bb20:		; preds = %bb19
 	%0 = load i32* undef, align 4		; <i32> [#uses=1]
-	%1 = sub i32 %0, undef		; <i32> [#uses=1]
+	%1 = sub i32 %0, %n		; <i32> [#uses=1]
 	br label %bb23
 
 bb21:		; preds = %bb23
-	%2 = icmp ult i8* %q.0, undef		; <i1> [#uses=1]
+	%2 = icmp ult i8* %q.0, %m		; <i1> [#uses=1]
 	br i1 %2, label %bb22, label %overflow2
 
 bb22:		; preds = %bb21

Copied: llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate8.ll (from r74072, llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate7.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate8.ll?p2=llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate8.ll&p1=llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate7.ll&r1=74072&r2=74073&rev=74073&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate7.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate8.ll Wed Jun 24 09:46:22 2009
@@ -1,5 +1,7 @@
-; RUN: llvm-as < %s | opt -indvars
-; PR4436
+; RUN: llvm-as < %s | opt -indvars | llvm-dis | not grep select
+
+; This loop has backedge-taken-count zero. Indvars shouldn't expand any
+; instructions to compute a trip count.
 
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
 target triple = "i386-pc-linux-gnu"

Propchange: llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate8.ll

------------------------------------------------------------------------------
    svn:mergeinfo = 





More information about the llvm-commits mailing list