Skip to content

Commit 7fa42da

Browse files
committed
loop guard non neg
1 parent 8f40ef3 commit 7fa42da

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11655,10 +11655,21 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
1165511655
P1 == CmpInst::getFlippedSignednessPredicate(P2);
1165611656
};
1165711657
if (IsSignFlippedPredicate(Pred, FoundPred)) {
11658+
// Try to make the isKnownNonNegative() etc queries below more precise by
11659+
// applying loop guards for the given context instruction.
11660+
const SCEV *FoundRHSGuarded = FoundRHS;
11661+
const SCEV *FoundLHSGuarded = FoundLHS;
11662+
Loop *L = CtxI ? LI.getLoopFor(CtxI->getParent()) : nullptr;
11663+
if (L) {
11664+
FoundRHSGuarded = applyLoopGuards(FoundRHS, L);
11665+
FoundLHSGuarded = applyLoopGuards(FoundLHS, L);
11666+
}
11667+
1165811668
// Unsigned comparison is the same as signed comparison when both the
1165911669
// operands are non-negative or negative.
11660-
if ((isKnownNonNegative(FoundLHS) && isKnownNonNegative(FoundRHS)) ||
11661-
(isKnownNegative(FoundLHS) && isKnownNegative(FoundRHS)))
11670+
if ((isKnownNonNegative(FoundLHSGuarded) &&
11671+
isKnownNonNegative(FoundRHSGuarded)) ||
11672+
(isKnownNegative(FoundLHSGuarded) && isKnownNegative(FoundRHSGuarded)))
1166211673
return isImpliedCondOperands(Pred, LHS, RHS, FoundLHS, FoundRHS, CtxI);
1166311674
// Create local copies that we can freely swap and canonicalize our
1166411675
// conditions to "le/lt".

0 commit comments

Comments
 (0)