aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorRamkumar Ramachandra <ramkumar.ramachandra@codasip.com>2025-02-10 13:31:18 +0000
committerGitHub <noreply@github.com>2025-02-10 13:31:18 +0000
commitc6b13a28717455028bf48bcb20f723ad3bbff783 (patch)
tree2a76b2908c406298fffc7a9b613f144945d9c122 /llvm/lib/Analysis/ScalarEvolution.cpp
parentaf2a228e0b5c9fbfa02f37f1be10800b17509617 (diff)
downloadllvm-c6b13a28717455028bf48bcb20f723ad3bbff783.zip
llvm-c6b13a28717455028bf48bcb20f723ad3bbff783.tar.gz
llvm-c6b13a28717455028bf48bcb20f723ad3bbff783.tar.bz2
Revert "SCEV: teach isImpliedViaOperations about samesign" (#126506)
The commit f5d24e6c is buggy, and following miscompiles have been reported: #126409 and https://github.com/llvm/llvm-project/pull/124270#issuecomment-2647222903 Revert it while we investigate.
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 46a5c44..573b052 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -11860,13 +11860,15 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
}
// Check whether the found predicate is the same as the desired predicate.
- if (auto P = CmpPredicate::getMatching(FoundPred, Pred))
- return isImpliedCondOperands(*P, LHS, RHS, FoundLHS, FoundRHS, CtxI);
+ // FIXME: use CmpPredicate::getMatching here.
+ if (FoundPred == static_cast<CmpInst::Predicate>(Pred))
+ return isImpliedCondOperands(Pred, LHS, RHS, FoundLHS, FoundRHS, CtxI);
// Check whether swapping the found predicate makes it the same as the
// desired predicate.
- if (auto P = CmpPredicate::getMatching(
- ICmpInst::getSwappedCmpPredicate(FoundPred), Pred)) {
+ // FIXME: use CmpPredicate::getMatching here.
+ if (ICmpInst::getSwappedCmpPredicate(FoundPred) ==
+ static_cast<CmpInst::Predicate>(Pred)) {
// We can write the implication
// 0. LHS Pred RHS <- FoundLHS SwapPred FoundRHS
// using one of the following ways:
@@ -11877,23 +11879,22 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
// Forms 1. and 2. require swapping the operands of one condition. Don't
// do this if it would break canonical constant/addrec ordering.
if (!isa<SCEVConstant>(RHS) && !isa<SCEVAddRecExpr>(LHS))
- return isImpliedCondOperands(ICmpInst::getSwappedCmpPredicate(*P), RHS,
- LHS, FoundLHS, FoundRHS, CtxI);
+ return isImpliedCondOperands(FoundPred, RHS, LHS, FoundLHS, FoundRHS,
+ CtxI);
if (!isa<SCEVConstant>(FoundRHS) && !isa<SCEVAddRecExpr>(FoundLHS))
- return isImpliedCondOperands(*P, LHS, RHS, FoundRHS, FoundLHS, CtxI);
+ return isImpliedCondOperands(Pred, LHS, RHS, FoundRHS, FoundLHS, CtxI);
// There's no clear preference between forms 3. and 4., try both. Avoid
// forming getNotSCEV of pointer values as the resulting subtract is
// not legal.
if (!LHS->getType()->isPointerTy() && !RHS->getType()->isPointerTy() &&
- isImpliedCondOperands(ICmpInst::getSwappedCmpPredicate(*P),
- getNotSCEV(LHS), getNotSCEV(RHS), FoundLHS,
- FoundRHS, CtxI))
+ isImpliedCondOperands(FoundPred, getNotSCEV(LHS), getNotSCEV(RHS),
+ FoundLHS, FoundRHS, CtxI))
return true;
if (!FoundLHS->getType()->isPointerTy() &&
!FoundRHS->getType()->isPointerTy() &&
- isImpliedCondOperands(*P, LHS, RHS, getNotSCEV(FoundLHS),
+ isImpliedCondOperands(Pred, LHS, RHS, getNotSCEV(FoundLHS),
getNotSCEV(FoundRHS), CtxI))
return true;
@@ -12569,16 +12570,14 @@ bool ScalarEvolution::isImpliedViaOperations(CmpPredicate Pred, const SCEV *LHS,
return false;
// We only want to work with GT comparison so far.
- if (ICmpInst::isLT(Pred)) {
+ if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_SLT) {
Pred = ICmpInst::getSwappedCmpPredicate(Pred);
std::swap(LHS, RHS);
std::swap(FoundLHS, FoundRHS);
}
- CmpInst::Predicate P = Pred.getPreferredSignedPredicate();
-
// For unsigned, try to reduce it to corresponding signed comparison.
- if (P == ICmpInst::ICMP_UGT)
+ if (Pred == ICmpInst::ICMP_UGT)
// We can replace unsigned predicate with its signed counterpart if all
// involved values are non-negative.
// TODO: We could have better support for unsigned.
@@ -12591,10 +12590,10 @@ bool ScalarEvolution::isImpliedViaOperations(CmpPredicate Pred, const SCEV *LHS,
FoundRHS) &&
isImpliedCondOperands(ICmpInst::ICMP_SGT, RHS, MinusOne, FoundLHS,
FoundRHS))
- P = ICmpInst::ICMP_SGT;
+ Pred = ICmpInst::ICMP_SGT;
}
- if (P != ICmpInst::ICMP_SGT)
+ if (Pred != ICmpInst::ICMP_SGT)
return false;
auto GetOpFromSExt = [&](const SCEV *S) {