[llvm] [ConstraintElim] Use cond from header as upper bound on IV in exit BB. (PR #94610)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 01:42:19 PDT 2024


================
@@ -1031,6 +1031,27 @@ void State::addInfoForInductions(BasicBlock &BB) {
   WorkList.push_back(FactOrCheck::getConditionFact(
       DTN, CmpInst::ICMP_SLT, PN, B,
       ConditionTy(CmpInst::ICMP_SLE, StartValue, B)));
+
+  assert(!StepOffset.isNegative() && "induction must be increasing");
+  // Try to add condition from header to the unique exit block, if there is one.
+  // When exiting either with EQ or NE, we know that the induction value must be
+  // u<= B, as a different exit may exit earlier.
+  ConditionTy Precond;
+  if (!MonotonicallyIncreasingUnsigned)
+    Precond = {CmpInst::ICMP_ULE, StartValue, B};
----------------
nikic wrote:

I'm confused, why do we only need this pre-condition if `!MonotonicallyIncreasingUnsigned`? Let's say we have a monotonic nuw addrec, a header eq exit where the start value is greater that is not taken and some other exit that is taken. Wouldn't we miscompile that?

https://github.com/llvm/llvm-project/pull/94610


More information about the llvm-commits mailing list