Skip to content

Conversation

dschuff
Copy link
Member

@dschuff dschuff commented Oct 6, 2025

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Oct 6, 2025

@llvm/pr-subscribers-backend-webassembly

Author: Derek Schuff (dschuff)

Changes

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 --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" }
 

Copy link
Contributor

@badumbatish badumbatish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for the catch Derek! Although i think it's missing the check labeling?

define i64 @other_intrinsic() #0 {
; CHECK-LABEL: other_intrinsic:
; CHECK:         .functype other_intrinsic () -> (i64)
; CHECK-NEXT:  # %bb.0: # %entry
; CHECK-NEXT:    global.get $push0=, __tls_align
; CHECK-NEXT:    return $pop0
entry:
  %0 = call i64 @llvm.wasm.tls.align.i64()
  ret i64 %0
}

@dschuff
Copy link
Member Author

dschuff commented Oct 7, 2025

Ah, right I was only checking for crashes and forgot to run it thorough the test updater, thanks!

@dschuff
Copy link
Member Author

dschuff commented Oct 7, 2025

Oh and github review protip, in case you didn't know: if you go to the trouble of figuring out what the PR should have included (thanks btw!), you can add that as a suggestion directly in the review (see doc, item 8, it's very easy to miss).

@dschuff dschuff enabled auto-merge (squash) October 7, 2025 23:20
@dschuff dschuff merged commit abc8aac into llvm:main Oct 7, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants