[llvm] [WebAssembly] Fold any/alltrue (setcc x, 0, eq/ne) to [not] any/alltrue x (PR #144741)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 1 13:47:50 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);
+  auto CombineSetCC =
+      [&N, &DAG, &DL](Intrinsic::WASMIntrinsics InPre, ISD::CondCode SetType,
+                      Intrinsic::WASMIntrinsics InPost) -> 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();
----------------
badumbatish wrote:

will perform a precheck before the lambda


https://github.com/llvm/llvm-project/pull/144741


More information about the llvm-commits mailing list