diff options
author | Pawel Wodnicki <pawel@32bitmicro.com> | 2012-11-30 03:38:58 +0000 |
---|---|---|
committer | Pawel Wodnicki <pawel@32bitmicro.com> | 2012-11-30 03:38:58 +0000 |
commit | b6a86811d0ef74d3eac5508a45c515a31256932b (patch) | |
tree | 549cf1c41b8443458e8686141ab8da77d9a7bb5a | |
parent | 2a75f42581c5cbca35d7396f9aebe9e3bacd15e7 (diff) |
Merging r168921: into the 3.2 release branch.upstream/llvmorg-3.2.0-rc2llvmorg-3.2.0-rc2
Follow up to 168711: It's safe to base this analysis on the found compare, just return the value for the right predicate.
Thanks to Andy for catching this.
llvm-svn: 168974
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 7 | ||||
-rw-r--r-- | llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll | 49 |
2 files changed, 52 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index e3ec2685cc9e..e3189ecc8994 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -6149,10 +6149,9 @@ bool ScalarEvolution::isImpliedCond(ICmpInst::Predicate Pred, if (SimplifyICmpOperands(Pred, LHS, RHS)) if (LHS == RHS) return CmpInst::isTrueWhenEqual(Pred); - - // Canonicalize the found cond too. We can't conclude a result from the - // simplified values. - SimplifyICmpOperands(FoundPred, FoundLHS, FoundRHS); + if (SimplifyICmpOperands(FoundPred, FoundLHS, FoundRHS)) + if (FoundLHS == FoundRHS) + return CmpInst::isFalseWhenEqual(FoundPred); // Check to see if we can make the LHS or RHS match. if (LHS == FoundRHS || RHS == FoundLHS) { diff --git a/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll b/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll index 923e5914405f..5dca71264665 100644 --- a/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll +++ b/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll @@ -160,3 +160,52 @@ unrolledend: ; preds = %forcond38 } declare void @llvm.trap() noreturn nounwind + +; In this case the second loop only has a single iteration, fold the header away +; CHECK: @func_12 +; CHECK: %tmp5 = icmp slt i32 %__key6.0, 10 +; CHECK: br i1 true, label %noassert68, label %unrolledend +define i32 @func_12() nounwind uwtable { +entry: + br label %forcond + +forcond: ; preds = %noassert, %entry + %__key6.0 = phi i32 [ 2, %entry ], [ %tmp37, %noassert ] + %tmp5 = icmp slt i32 %__key6.0, 10 + br i1 %tmp5, label %noassert, label %forcond38.preheader + +forcond38.preheader: ; preds = %forcond + br label %forcond38 + +noassert: ; preds = %forbody + %tmp13 = sdiv i32 -32768, %__key6.0 + %tmp2936 = shl i32 %tmp13, 24 + %sext23 = shl i32 %tmp13, 24 + %tmp32 = icmp eq i32 %tmp2936, %sext23 + %tmp37 = add i32 %__key6.0, 1 + br i1 %tmp32, label %forcond, label %assert33 + +assert33: ; preds = %noassert + tail call void @llvm.trap() + unreachable + +forcond38: ; preds = %noassert68, %forcond38.preheader + %__key8.0 = phi i32 [ %tmp81, %noassert68 ], [ 2, %forcond38.preheader ] + %tmp46 = icmp slt i32 %__key8.0, 10 + br i1 %tmp46, label %noassert68, label %unrolledend + +noassert68: ; preds = %forbody39 + %tmp57 = sdiv i32 -32768, %__key8.0 + %sext34 = shl i32 %tmp57, 16 + %sext21 = shl i32 %tmp57, 16 + %tmp76 = icmp ne i32 %sext34, %sext21 + %tmp81 = add i32 %__key8.0, 1 + br i1 %tmp76, label %forcond38, label %assert77 + +assert77: ; preds = %noassert68 + tail call void @llvm.trap() + unreachable + +unrolledend: ; preds = %forcond38 + ret i32 0 +} |