[llvm] [WebAssembly] Check intrinsic argument count before Any/All combine (PR #162163)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 6 14:29:15 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-webassembly

Author: Derek Schuff (dschuff)

<details>
<summary>Changes</summary>

This code is activated on all INTRINSIC_WO_CHAIN but only handles
a selection. However it was trying to read the arguments before
checking which intrinsic it was handling. This fails for intrinsics
that have no arguments.


---
Full diff: https://github.com/llvm/llvm-project/pull/162163.diff


2 Files Affected:

- (modified) llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (+2-1) 
- (modified) llvm/test/CodeGen/WebAssembly/simd-setcc-reductions.ll (+8) 


``````````diff
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index 163bf9ba5b089..64723340051b8 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -3209,7 +3209,8 @@ static SDValue performAnyAllCombine(SDNode *N, SelectionDAG &DAG) {
   using namespace llvm::SDPatternMatch;
 
   SDValue LHS;
-  if (!sd_match(N->getOperand(1),
+  if (N->getNumOperands() < 2 ||
+      !sd_match(N->getOperand(1),
                 m_c_SetCC(m_Value(LHS), m_Zero(), m_CondCode())))
     return SDValue();
   EVT LT = LHS.getValueType();
diff --git a/llvm/test/CodeGen/WebAssembly/simd-setcc-reductions.ll b/llvm/test/CodeGen/WebAssembly/simd-setcc-reductions.ll
index 172ff53bfb458..e4156e4776132 100644
--- a/llvm/test/CodeGen/WebAssembly/simd-setcc-reductions.ll
+++ b/llvm/test/CodeGen/WebAssembly/simd-setcc-reductions.ll
@@ -132,4 +132,12 @@ define i32 @all_true_2_4_i32(<4 x i32> %v) {
   ret i32 %conv3
 }
 
+; Regression test for the intrinsic pattern matcher with nullary intrinsics
+define i64 @other_intrinsic() #0 {
+entry:
+  %0 = call i64 @llvm.wasm.tls.align.i64()
+  ret i64 %0
+}
+
+attributes #0 = { "target-features"="+atomics" }
 

``````````

</details>


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


More information about the llvm-commits mailing list