diff options
| author | Dan Gohman <gohman@apple.com> | 2009-06-24 14:46:22 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-06-24 14:46:22 +0000 |
| commit | f57bdb75d4dd60773b63eff8a143aa6846a56afe (patch) | |
| tree | 69692604c15f35891d0b7c5a177ebb79e23e9c82 /llvm | |
| parent | 929fa7b0f4b6f57ecabb57ac1010dce84a4c8f31 (diff) | |
| download | bcm5719-llvm-f57bdb75d4dd60773b63eff8a143aa6846a56afe.tar.gz bcm5719-llvm-f57bdb75d4dd60773b63eff8a143aa6846a56afe.zip | |
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.
llvm-svn: 74073
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 12 | ||||
| -rw-r--r-- | llvm/test/Transforms/IndVarSimplify/loop_evaluate7.ll | 6 | ||||
| -rw-r--r-- | llvm/test/Transforms/IndVarSimplify/loop_evaluate8.ll | 63 |
3 files changed, 76 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 3bbeb95212e..6ac6efa1b85 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -1690,10 +1690,14 @@ ScalarEvolution::getSMaxExpr(SmallVectorImpl<const SCEV*> &Ops) { 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 @@ ScalarEvolution::getUMaxExpr(SmallVectorImpl<const SCEV*> &Ops) { 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]; } } diff --git a/llvm/test/Transforms/IndVarSimplify/loop_evaluate7.ll b/llvm/test/Transforms/IndVarSimplify/loop_evaluate7.ll index bce65e047da..6e31c55d526 100644 --- a/llvm/test/Transforms/IndVarSimplify/loop_evaluate7.ll +++ b/llvm/test/Transforms/IndVarSimplify/loop_evaluate7.ll @@ -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 @@ bb19: ; preds = %bb30 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 diff --git a/llvm/test/Transforms/IndVarSimplify/loop_evaluate8.ll b/llvm/test/Transforms/IndVarSimplify/loop_evaluate8.ll new file mode 100644 index 00000000000..fa2f9e57f07 --- /dev/null +++ b/llvm/test/Transforms/IndVarSimplify/loop_evaluate8.ll @@ -0,0 +1,63 @@ +; 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" + +define i8* @string_expandtabs() nounwind { +entry: + br i1 undef, label %bb33, label %bb1 + +bb1: ; preds = %entry + br i1 undef, label %overflow1, label %bb15 + +bb15: ; preds = %bb1 + br i1 undef, label %bb33, label %bb17 + +bb17: ; preds = %bb15 + br label %bb30 + +bb19: ; preds = %bb30 + br i1 undef, label %bb20, label %bb29 + +bb20: ; preds = %bb19 + %0 = load i32* undef, align 4 ; <i32> [#uses=1] + %1 = sub i32 %0, undef ; <i32> [#uses=1] + br label %bb23 + +bb21: ; preds = %bb23 + %2 = icmp ult i8* %q.0, undef ; <i1> [#uses=1] + br i1 %2, label %bb22, label %overflow2 + +bb22: ; preds = %bb21 + %3 = getelementptr i8* %q.0, i32 1 ; <i8*> [#uses=1] + br label %bb23 + +bb23: ; preds = %bb22, %bb20 + %i.2 = phi i32 [ %1, %bb20 ], [ %4, %bb22 ] ; <i32> [#uses=1] + %q.0 = phi i8* [ undef, %bb20 ], [ %3, %bb22 ] ; <i8*> [#uses=3] + %4 = add i32 %i.2, -1 ; <i32> [#uses=2] + %5 = icmp eq i32 %4, -1 ; <i1> [#uses=1] + br i1 %5, label %bb29, label %bb21 + +bb29: ; preds = %bb23, %bb19 + %q.1 = phi i8* [ undef, %bb19 ], [ %q.0, %bb23 ] ; <i8*> [#uses=0] + br label %bb30 + +bb30: ; preds = %bb29, %bb17 + br i1 undef, label %bb19, label %bb33 + +overflow2: ; preds = %bb21 + br i1 undef, label %bb32, label %overflow1 + +bb32: ; preds = %overflow2 + br label %overflow1 + +overflow1: ; preds = %bb32, %overflow2, %bb1 + ret i8* null + +bb33: ; preds = %bb30, %bb15, %entry + ret i8* undef +} |

