llvm.org GIT mirror llvm / 99dd56e
[SCEV] Fix predicate usage in computeExitLimitFromICmp In this method, we invoke `SimplifyICmpOperands` which takes the `Cond` predicate by reference and may change it along with `LHS` and `RHS` SCEVs. But then we invoke `computeShiftCompareExitLimit` with Values from which the SCEVs have been derived, these Values have not been modified while `Cond` could be. One of possible outcomes of this is that we may falsely prove that an infinite loop ends within some finite number of iterations. In this patch, we save the original `Cond` and pass it along with original operands. This logic may be removed in future once `computeShiftCompareExitLimit` works with SCEVs instead of value operands. Reviewed By: sanjoy Differential Revision: https://reviews.llvm.org/D40953 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320142 91177308-0d34-0410-b5e6-96231b3b80d8 Max Kazantsev 2 years ago
2 changed file(s) with 21 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
70737073 Cond = ExitCond->getPredicate();
70747074 else
70757075 Cond = ExitCond->getInversePredicate();
7076 const ICmpInst::Predicate OriginalCond = Cond;
70767077
70777078 // Handle common loops like: for (X = "string"; *X; ++X)
70787079 if (LoadInst *LI = dyn_cast(ExitCond->getOperand(0)))
71567157 return ExhaustiveCount;
71577158
71587159 return computeShiftCompareExitLimit(ExitCond->getOperand(0),
7159 ExitCond->getOperand(1), L, Cond);
7160 ExitCond->getOperand(1), L, OriginalCond);
71607161 }
71617162
71627163 ScalarEvolution::ExitLimit
159159 ret void
160160 }
161161
162 define void @test9() {
163 ; CHECK-LABEL: Determining loop execution counts for: @test9
164 ; CHECK: Loop %loop: Unpredictable max backedge-taken count.
165
166 ; This is an infinite loop, make sure that it recognized as such.
167
168 entry:
169 br label %loop
170
171 leave:
172 ret void
173
174 loop:
175 %iv = phi i32 [ -20, %entry ], [ %iv.shift, %loop ]
176 %iv.shift = ashr i32 %iv, 1
177 %exit.cond = icmp sgt i32 %iv, -1
178 br i1 %exit.cond, label %leave, label %loop
179 }
180
162181 !0 = !{i32 0, i32 50000}
163182 !1 = !{i32 -5000, i32 -1}