Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from MaxMood96:main #141

Merged
merged 13 commits into from
Oct 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[InstCombine] move fold for "(X-Y) == 0"; NFC
This consolidates related folds that all have a
similar use restriction that may not be necessary.
  • Loading branch information
rotateright committed Oct 10, 2021
commit 05281d95f2385fd7e266c1b439e5045f0187b149
15 changes: 7 additions & 8 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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()) {
Expand Down