forked from OSchip/llvm-project
[InstCombine] move fold for "(X-Y) == 0"; NFC
This consolidates related folds that all have a similar use restriction that may not be necessary.
This commit is contained in:
parent
cbd8041b0b
commit
05281d95f2
|
@ -2602,9 +2602,16 @@ Instruction *InstCombinerImpl::foldICmpSubConstant(ICmpInst &Cmp,
|
|||
|
||||
// The following transforms are only worth it if the only user of the subtract
|
||||
// is the icmp.
|
||||
// TODO: This is an artificial restriction for all of the transforms below
|
||||
// that only need a single replacement icmp.
|
||||
if (!Sub->hasOneUse())
|
||||
return nullptr;
|
||||
|
||||
// X - Y == 0 --> X == Y.
|
||||
// X - Y != 0 --> X != Y.
|
||||
if (Cmp.isEquality() && C.isZero())
|
||||
return new ICmpInst(Pred, X, Y);
|
||||
|
||||
if (Sub->hasNoSignedWrap()) {
|
||||
// (icmp sgt (sub nsw X, Y), -1) -> (icmp sge X, Y)
|
||||
if (Pred == ICmpInst::ICMP_SGT && C.isAllOnes())
|
||||
|
@ -3130,14 +3137,6 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(
|
|||
}
|
||||
}
|
||||
break;
|
||||
case Instruction::Sub:
|
||||
if (BO->hasOneUse()) {
|
||||
if (C.isZero()) {
|
||||
// Replace ((sub A, B) != 0) with (A != B).
|
||||
return new ICmpInst(Pred, BOp0, BOp1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Instruction::Or: {
|
||||
const APInt *BOC;
|
||||
if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {
|
||||
|
|
Loading…
Reference in New Issue