[llvm] [WebAssembly] [Backend] Wasm optimize illegal bitmask (PR #145627)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 02:18:35 PDT 2025


================
@@ -3236,6 +3244,48 @@ static SDValue performBitcastCombine(SDNode *N,
         DL, VT);
   }
 
+  // bitcast <N x i1>(setcc ...) to concat iN, where N = 32 and 64 (illegal)
+  if (NumElts == 32 || NumElts == 64) {
+    // Strategy: We will setcc them seperately in v16i8 -> v16i1
+    // Bitcast them to i16, extend them to either i32 or i64.
+    // Add them together, shifting left 1 by 1.
+    SDValue Concat, SetCCVector;
+    ISD::CondCode SetCond;
+
+    if (!sd_match(N, m_BitCast(m_c_SetCC(m_Value(Concat),
+                                         m_VectorVT(m_Value(SetCCVector)),
+                                         m_CondCode(SetCond)))))
+      return SDValue();
+    if (Concat.getOpcode() != ISD::CONCAT_VECTORS)
+      return SDValue();
+    // CHECK IF VECTOR is a constant, i.e all values are the same
+    if (!ISD::isBuildVectorOfConstantSDNodes(SetCCVector.getNode()))
+      return SDValue();
----------------
lukel97 wrote:

I'm also wondering is there a reason why SetCCVector needs to be a splat to begin with? Could we allow non-constant, non-splat vectors if we extracted a v16i8 subvector instead with ISD::extract_subvector?

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


More information about the llvm-commits mailing list