[llvm] [SLP]Booleanize logical and/or nodes in the wide leaf type (PR #223250)
Ryan Buchner via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 23:39:13 PDT 2026
================
@@ -18222,6 +18239,133 @@ static T *performExtractsShuffleAction(
return Prev;
}
+void BoUpSLP::detectBooleanizedNodes() {
+ // An absorbable boolean leaf is a one-use trunc of a wide value or a
+ // one-use zero-test of a value from [0, 1]; bit 0 of the wide value is the
+ // i1 lane value in both cases.
+ auto GetBoolLeafWideTy = [&](const TreeEntry *OpE) -> Type * {
+ if (OpE->State != TreeEntry::Vectorize || OpE->isAltShuffle() ||
+ OpE->hasCopyableElements() || !OpE->ReuseShuffleIndices.empty() ||
+ OpE->CombinedOp != TreeEntry::NotCombinedOp)
+ return nullptr;
+ unsigned WideOpIdx;
+ bool IsZeroTest = OpE->getOpcode() == Instruction::ICmp;
+ if (OpE->getOpcode() == Instruction::Trunc) {
+ if (!all_of(OpE->Scalars, [](Value *V) {
+ return match(V, m_OneUse(m_Trunc(m_Value())));
+ }))
+ return nullptr;
+ WideOpIdx = 0;
+ } else if (IsZeroTest) {
+ if (!all_of(OpE->Scalars, [](Value *V) {
+ auto *CI = dyn_cast<ICmpInst>(V);
+ return CI && CI->hasOneUse() &&
+ CI->getPredicate() == ICmpInst::ICMP_NE;
+ }))
+ return nullptr;
+ if (all_of(OpE->getOperand(0),
+ [](Value *V) { return match(V, m_Zero()); }))
+ WideOpIdx = 1;
+ else if (all_of(OpE->getOperand(1),
+ [](Value *V) { return match(V, m_Zero()); }))
+ WideOpIdx = 0;
+ else
+ return nullptr;
+ } else {
+ return nullptr;
+ }
+ Type *WideTy = nullptr;
+ for (Value *W : OpE->getOperand(WideOpIdx)) {
+ if (!W->getType()->isIntegerTy() || (WideTy && W->getType() != WideTy) ||
+ !isGuaranteedNotToBePoison(W) ||
+ (IsZeroTest && computeKnownBits(W, *DL).getMaxValue() != 1))
+ return nullptr;
+ WideTy = W->getType();
----------------
bababuck wrote:
Nit: Could set `WideTy` just once before loop.
https://github.com/llvm/llvm-project/pull/223250
More information about the llvm-commits
mailing list