[llvm] [WebAssembly] Fold any/alltrue (setcc x, 0, eq/ne) to [not] any/alltrue x (PR #144741)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 30 02:38:32 PDT 2025
================
@@ -3239,6 +3240,55 @@ static SDValue performBitcastCombine(SDNode *N,
return SDValue();
}
+static SDValue performAnyAllCombine(SDNode *N, SelectionDAG &DAG) {
+ // any_true (setcc <X>, 0, eq) => (not (all_true X))
+ // all_true (setcc <X>, 0, eq) => (not (any_true X))
+ // any_true (setcc <X>, 0, ne) => (any_true X)
+ // all_true (setcc <X>, 0, ne) => (all_true X)
+ assert(N->getOpcode() == ISD::INTRINSIC_WO_CHAIN);
+ using namespace llvm::SDPatternMatch;
+ SDLoc DL(N);
+ static auto SimdCombiner =
+ [&](Intrinsic::WASMIntrinsics InPre, ISD::CondCode SetType,
+ Intrinsic::WASMIntrinsics InPost, bool ShouldInvert) -> SDValue {
+ if (N->getConstantOperandVal(0) != InPre)
+ return SDValue();
+
+ SDValue LHS;
+ if (!sd_match(N->getOperand(1), m_c_SetCC(m_Value(LHS), m_Zero(),
+ m_SpecificCondCode(SetType))))
+ return SDValue();
+
+ EVT LT = LHS.getValueType();
+ unsigned NumElts = LT.getVectorNumElements();
+ if (LT.getScalarSizeInBits() > 128 / NumElts)
+ return SDValue();
+
+ SDValue Ret = DAG.getZExtOrTrunc(
+ DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, MVT::i32,
+ {DAG.getConstant(InPost, DL, MVT::i32), LHS}),
+ DL, MVT::i1);
+ if (ShouldInvert)
----------------
lukel97 wrote:
I think you can remove `ShouldInvert` if you just directly check the CondCode,
```suggestion
if (SetType == ISD::SETEQ)
```
https://github.com/llvm/llvm-project/pull/144741
More information about the llvm-commits
mailing list