Skip to content

Commit 24d616e

Browse files
committed
Merging r168921: into the 3.2 release branch.
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@168974 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 73c4842 commit 24d616e

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

lib/Analysis/ScalarEvolution.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6149,10 +6149,9 @@ bool ScalarEvolution::isImpliedCond(ICmpInst::Predicate Pred,
61496149
if (SimplifyICmpOperands(Pred, LHS, RHS))
61506150
if (LHS == RHS)
61516151
return CmpInst::isTrueWhenEqual(Pred);
6152-
6153-
// Canonicalize the found cond too. We can't conclude a result from the
6154-
// simplified values.
6155-
SimplifyICmpOperands(FoundPred, FoundLHS, FoundRHS);
6152+
if (SimplifyICmpOperands(FoundPred, FoundLHS, FoundRHS))
6153+
if (FoundLHS == FoundRHS)
6154+
return CmpInst::isFalseWhenEqual(FoundPred);
61566155

61576156
// Check to see if we can make the LHS or RHS match.
61586157
if (LHS == FoundRHS || RHS == FoundLHS) {

test/Transforms/IndVarSimplify/eliminate-comparison.ll

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,52 @@ unrolledend: ; preds = %forcond38
160160
}
161161

162162
declare void @llvm.trap() noreturn nounwind
163+
164+
; In this case the second loop only has a single iteration, fold the header away
165+
; CHECK: @func_12
166+
; CHECK: %tmp5 = icmp slt i32 %__key6.0, 10
167+
; CHECK: br i1 true, label %noassert68, label %unrolledend
168+
define i32 @func_12() nounwind uwtable {
169+
entry:
170+
br label %forcond
171+
172+
forcond: ; preds = %noassert, %entry
173+
%__key6.0 = phi i32 [ 2, %entry ], [ %tmp37, %noassert ]
174+
%tmp5 = icmp slt i32 %__key6.0, 10
175+
br i1 %tmp5, label %noassert, label %forcond38.preheader
176+
177+
forcond38.preheader: ; preds = %forcond
178+
br label %forcond38
179+
180+
noassert: ; preds = %forbody
181+
%tmp13 = sdiv i32 -32768, %__key6.0
182+
%tmp2936 = shl i32 %tmp13, 24
183+
%sext23 = shl i32 %tmp13, 24
184+
%tmp32 = icmp eq i32 %tmp2936, %sext23
185+
%tmp37 = add i32 %__key6.0, 1
186+
br i1 %tmp32, label %forcond, label %assert33
187+
188+
assert33: ; preds = %noassert
189+
tail call void @llvm.trap()
190+
unreachable
191+
192+
forcond38: ; preds = %noassert68, %forcond38.preheader
193+
%__key8.0 = phi i32 [ %tmp81, %noassert68 ], [ 2, %forcond38.preheader ]
194+
%tmp46 = icmp slt i32 %__key8.0, 10
195+
br i1 %tmp46, label %noassert68, label %unrolledend
196+
197+
noassert68: ; preds = %forbody39
198+
%tmp57 = sdiv i32 -32768, %__key8.0
199+
%sext34 = shl i32 %tmp57, 16
200+
%sext21 = shl i32 %tmp57, 16
201+
%tmp76 = icmp ne i32 %sext34, %sext21
202+
%tmp81 = add i32 %__key8.0, 1
203+
br i1 %tmp76, label %forcond38, label %assert77
204+
205+
assert77: ; preds = %noassert68
206+
tail call void @llvm.trap()
207+
unreachable
208+
209+
unrolledend: ; preds = %forcond38
210+
ret i32 0
211+
}

0 commit comments

Comments
 (0)