[PATCH] D148412: [InstCombine] Cleanup code in foldSelectICmpAndOr; NFC
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 14 23:11:59 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: majnemer, spatel, nikic, craig.topper.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
There was just alot of boolean logic to propegate conditions that seem
clearer in conditions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D148412
Files:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Index: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -663,13 +663,14 @@
V = CmpLHS;
C1Log = C1->logBase2();
IsEqualZero = IC->getPredicate() == ICmpInst::ICMP_EQ;
- } else if (IC->getPredicate() == ICmpInst::ICMP_SLT ||
- IC->getPredicate() == ICmpInst::ICMP_SGT) {
+ } else {
// We also need to recognize (icmp slt (trunc (X)), 0) and
// (icmp sgt (trunc (X)), -1).
- IsEqualZero = IC->getPredicate() == ICmpInst::ICMP_SGT;
- if ((IsEqualZero && !match(CmpRHS, m_AllOnes())) ||
- (!IsEqualZero && !match(CmpRHS, m_Zero())))
+ if (IC->getPredicate() == ICmpInst::ICMP_SGT && match(CmpRHS, m_AllOnes()))
+ IsEqualZero = true;
+ if (IC->getPredicate() == ICmpInst::ICMP_SLT && match(CmpRHS, m_Zero()))
+ IsEqualZero = false;
+ else
return nullptr;
if (!match(CmpLHS, m_OneUse(m_Trunc(m_Value(V)))))
@@ -677,30 +678,30 @@
C1Log = CmpLHS->getType()->getScalarSizeInBits() - 1;
NeedAnd = true;
- } else {
- return nullptr;
}
+ Value *Or, *Y;
const APInt *C2;
- bool OrOnTrueVal = false;
- bool OrOnFalseVal = match(FalseVal, m_Or(m_Specific(TrueVal), m_Power2(C2)));
- if (!OrOnFalseVal)
- OrOnTrueVal = match(TrueVal, m_Or(m_Specific(FalseVal), m_Power2(C2)));
-
- if (!OrOnFalseVal && !OrOnTrueVal)
+ bool NeedXor;
+ if (match(FalseVal, m_Or(m_Specific(TrueVal), m_Power2(C2)))) {
+ Y = TrueVal;
+ Or = FalseVal;
+ NeedXor = !IsEqualZero;
+ } else if (match(TrueVal, m_Or(m_Specific(FalseVal), m_Power2(C2)))) {
+ Y = FalseVal;
+ Or = TrueVal;
+ NeedXor = IsEqualZero;
+ } else {
return nullptr;
-
- Value *Y = OrOnFalseVal ? TrueVal : FalseVal;
+ }
unsigned C2Log = C2->logBase2();
- bool NeedXor = (!IsEqualZero && OrOnFalseVal) || (IsEqualZero && OrOnTrueVal);
bool NeedShift = C1Log != C2Log;
bool NeedZExtTrunc = Y->getType()->getScalarSizeInBits() !=
V->getType()->getScalarSizeInBits();
// Make sure we don't create more instructions than we save.
- Value *Or = OrOnFalseVal ? FalseVal : TrueVal;
if ((NeedShift + NeedXor + NeedZExtTrunc) >
(IC->hasOneUse() + Or->hasOneUse()))
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148412.513847.patch
Type: text/x-patch
Size: 2398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230415/32417364/attachment.bin>
More information about the llvm-commits
mailing list