mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-19 13:16:46 +00:00
[IR] Add helper CmpPredicate::dropSameSign
(#134071)
Address review comment https://github.com/llvm/llvm-project/pull/133711#discussion_r2024519641
This commit is contained in:
parent
f186041553
commit
65ed35393c
@ -41,6 +41,10 @@ public:
|
||||
/// Query samesign information, for optimizations.
|
||||
bool hasSameSign() const { return HasSameSign; }
|
||||
|
||||
/// Drops samesign information. This is used when the samesign information
|
||||
/// should be dropped explicitly.
|
||||
CmpInst::Predicate dropSameSign() const { return Pred; }
|
||||
|
||||
/// Compares two CmpPredicates taking samesign into account and returns the
|
||||
/// canonicalized CmpPredicate if they match. An alternative to operator==.
|
||||
///
|
||||
|
@ -11622,7 +11622,7 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
|
||||
// to prove non-equality and non-strict comparison separately.
|
||||
CmpPredicate NonStrictPredicate = ICmpInst::getNonStrictCmpPredicate(Pred);
|
||||
const bool ProvingStrictComparison =
|
||||
(Pred != static_cast<CmpInst::Predicate>(NonStrictPredicate));
|
||||
Pred != NonStrictPredicate.dropSameSign();
|
||||
bool ProvedNonStrictComparison = false;
|
||||
bool ProvedNonEquality = false;
|
||||
|
||||
@ -11792,9 +11792,8 @@ bool ScalarEvolution::isImpliedCond(CmpPredicate Pred, const SCEV *LHS,
|
||||
const SCEV *TruncFoundLHS = getTruncateExpr(FoundLHS, NarrowType);
|
||||
const SCEV *TruncFoundRHS = getTruncateExpr(FoundRHS, NarrowType);
|
||||
// We cannot preserve samesign after truncation.
|
||||
if (isImpliedCondBalancedTypes(
|
||||
Pred, LHS, RHS, static_cast<ICmpInst::Predicate>(FoundPred),
|
||||
TruncFoundLHS, TruncFoundRHS, CtxI))
|
||||
if (isImpliedCondBalancedTypes(Pred, LHS, RHS, FoundPred.dropSameSign(),
|
||||
TruncFoundLHS, TruncFoundRHS, CtxI))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -5641,7 +5641,7 @@ Instruction *InstCombinerImpl::foldICmpWithMinMax(Instruction &I,
|
||||
// execute comparisons. For example, `icmp samesign ult umax(X, -46), -32`
|
||||
// cannot be decomposed into `(icmp samesign ult X, -46) or (icmp samesign ult
|
||||
// -46, -32)`. `X` is allowed to be non-negative here.
|
||||
Pred = static_cast<CmpInst::Predicate>(Pred);
|
||||
Pred = Pred.dropSameSign();
|
||||
auto CmpXZ = IsCondKnownTrue(simplifyICmpInst(Pred, X, Z, Q));
|
||||
auto CmpYZ = IsCondKnownTrue(simplifyICmpInst(Pred, Y, Z, Q));
|
||||
if (!CmpXZ.has_value() && !CmpYZ.has_value())
|
||||
|
Loading…
x
Reference in New Issue
Block a user