[llvm] a512c89 - [NFC][InstCombine] Refactor '(-NSW x) pred x' fold
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 01:51:58 PDT 2020
Author: Roman Lebedev
Date: 2020-08-06T11:50:36+03:00
New Revision: a512c894768ba681721cb2fc5159294cec810f0a
URL: https://github.com/llvm/llvm-project/commit/a512c894768ba681721cb2fc5159294cec810f0a
DIFF: https://github.com/llvm/llvm-project/commit/a512c894768ba681721cb2fc5159294cec810f0a.diff
LOG: [NFC][InstCombine] Refactor '(-NSW x) pred x' fold
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 66977cc3fce8..77e38236686b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3725,60 +3725,14 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
if (!match(&I, m_c_ICmp(Pred, m_NSWNeg(m_Value(X)), m_Deferred(X))))
return nullptr;
- CmpInst::Predicate NewPred;
- Constant *NewRHS;
- switch (Pred) {
- case ICmpInst::ICMP_SGT:
- NewPred = ICmpInst::ICMP_SLT;
- NewRHS = Constant::getNullValue(X->getType());
- break;
-
- case ICmpInst::ICMP_SGE:
- NewPred = ICmpInst::ICMP_SLE;
- NewRHS = Constant::getNullValue(X->getType());
- break;
-
- case ICmpInst::ICMP_SLT:
- NewPred = ICmpInst::ICMP_SGT;
- NewRHS = Constant::getNullValue(X->getType());
- break;
-
- case ICmpInst::ICMP_SLE:
- NewPred = ICmpInst::ICMP_SGE;
- NewRHS = Constant::getNullValue(X->getType());
- break;
-
- case ICmpInst::ICMP_UGT:
- NewPred = ICmpInst::ICMP_SGT;
- NewRHS = Constant::getNullValue(X->getType());
- break;
-
- case ICmpInst::ICMP_UGE:
- NewPred = ICmpInst::ICMP_SGE;
- NewRHS = Constant::getNullValue(X->getType());
- break;
-
- case ICmpInst::ICMP_ULT:
- NewPred = ICmpInst::ICMP_SLT;
- NewRHS = Constant::getNullValue(X->getType());
- break;
-
- case ICmpInst::ICMP_ULE:
- NewPred = ICmpInst::ICMP_SLE;
- NewRHS = Constant::getNullValue(X->getType());
- break;
-
- case ICmpInst::ICMP_EQ:
- case ICmpInst::ICMP_NE:
- NewPred = Pred;
- NewRHS = Constant::getNullValue(X->getType());
- break;
-
- default:
- return nullptr;
- }
+ if (ICmpInst::isSigned(Pred))
+ Pred = ICmpInst::getSwappedPredicate(Pred);
+ else if (ICmpInst::isUnsigned(Pred))
+ Pred = ICmpInst::getSignedPredicate(Pred);
+ // else for equality-comparisons just keep the predicate.
- return ICmpInst::Create(Instruction::ICmp, NewPred, X, NewRHS, I.getName());
+ return ICmpInst::Create(Instruction::ICmp, Pred, X,
+ Constant::getNullValue(X->getType()), I.getName());
}
/// Try to fold icmp (binop), X or icmp X, (binop).
More information about the llvm-commits
mailing list