Skip to content

Commit 73c4842

Browse files
committed
Merging r168711: into the 3.2 release branch.
SCEV: Even if the latch terminator is foldable we can't deduce the result of an unrelated condition with it. Fixes PR14432. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@168973 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f56817c commit 73c4842

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

lib/Analysis/ScalarEvolution.cpp

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

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

test/Transforms/IndVarSimplify/eliminate-comparison.ll

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,57 @@ loop:
106106
return:
107107
ret void
108108
}
109+
110+
; PR14432
111+
; Indvars should not turn the second loop into an infinite one.
112+
113+
; CHECK: @func_11
114+
; CHECK: %tmp5 = icmp slt i32 %__key6.0, 10
115+
; CHECK-NOT: br i1 true, label %noassert68, label %unrolledend
116+
117+
define i32 @func_11() nounwind uwtable {
118+
entry:
119+
br label %forcond
120+
121+
forcond: ; preds = %noassert, %entry
122+
%__key6.0 = phi i32 [ 2, %entry ], [ %tmp37, %noassert ]
123+
%tmp5 = icmp slt i32 %__key6.0, 10
124+
br i1 %tmp5, label %noassert, label %forcond38.preheader
125+
126+
forcond38.preheader: ; preds = %forcond
127+
br label %forcond38
128+
129+
noassert: ; preds = %forbody
130+
%tmp13 = sdiv i32 -32768, %__key6.0
131+
%tmp2936 = shl i32 %tmp13, 24
132+
%sext23 = shl i32 %tmp13, 24
133+
%tmp32 = icmp eq i32 %tmp2936, %sext23
134+
%tmp37 = add i32 %__key6.0, 1
135+
br i1 %tmp32, label %forcond, label %assert33
136+
137+
assert33: ; preds = %noassert
138+
tail call void @llvm.trap()
139+
unreachable
140+
141+
forcond38: ; preds = %noassert68, %forcond38.preheader
142+
%__key8.0 = phi i32 [ %tmp81, %noassert68 ], [ 2, %forcond38.preheader ]
143+
%tmp46 = icmp slt i32 %__key8.0, 10
144+
br i1 %tmp46, label %noassert68, label %unrolledend
145+
146+
noassert68: ; preds = %forbody39
147+
%tmp57 = sdiv i32 -32768, %__key8.0
148+
%sext34 = shl i32 %tmp57, 16
149+
%sext21 = shl i32 %tmp57, 16
150+
%tmp76 = icmp eq i32 %sext34, %sext21
151+
%tmp81 = add i32 %__key8.0, 1
152+
br i1 %tmp76, label %forcond38, label %assert77
153+
154+
assert77: ; preds = %noassert68
155+
tail call void @llvm.trap()
156+
unreachable
157+
158+
unrolledend: ; preds = %forcond38
159+
ret i32 0
160+
}
161+
162+
declare void @llvm.trap() noreturn nounwind

0 commit comments

Comments
 (0)