[llvm] 3b24769 - [WASM] Prevent casting `undef` to `CosntantSDNode`

Peter Rong via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 30 20:14:17 PDT 2023


Author: Peter Rong
Date: 2023-03-30T20:14:11-07:00
New Revision: 3b2476910ba33f1112c1b915b3cf41033ffd7e1a

URL: https://github.com/llvm/llvm-project/commit/3b2476910ba33f1112c1b915b3cf41033ffd7e1a
DIFF: https://github.com/llvm/llvm-project/commit/3b2476910ba33f1112c1b915b3cf41033ffd7e1a.diff

LOG: [WASM] Prevent casting `undef` to `CosntantSDNode`

WebAssembly tries to cast an `undef` to `CosntantSDNode` during `LowerAccessVectorElement`.
These operations will trigger an assertion error in cast.
To avoid this issue, we prevent casting, and abort the lowering operation.
A unit test is also included.

This patch fixes [pr61828](https://github.com/llvm/llvm-project/issues/61828)

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D147198

Added: 
    llvm/test/CodeGen/WebAssembly/pr61828.ll

Modified: 
    llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index 892478e3d706b..db34935871534 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -2242,7 +2242,7 @@ WebAssemblyTargetLowering::LowerAccessVectorElement(SDValue Op,
                                                     SelectionDAG &DAG) const {
   // Allow constant lane indices, expand variable lane indices
   SDNode *IdxNode = Op.getOperand(Op.getNumOperands() - 1).getNode();
-  if (isa<ConstantSDNode>(IdxNode) || IdxNode->isUndef()) {
+  if (isa<ConstantSDNode>(IdxNode)) {
     // Ensure the index type is i32 to match the tablegen patterns
     uint64_t Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue();
     SmallVector<SDValue, 3> Ops(Op.getNode()->ops());

diff  --git a/llvm/test/CodeGen/WebAssembly/pr61828.ll b/llvm/test/CodeGen/WebAssembly/pr61828.ll
new file mode 100644
index 0000000000000..8c40b445f61e2
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/pr61828.ll
@@ -0,0 +1,9 @@
+; RUN: llc < %s -mattr=+simd128 -mtriple=wasm64
+
+define void @foo(i64 %i0, i64 %i1, ptr %p) {
+  %B4 = urem i64 %i0, %i0
+  %B5 = udiv i64 %i1, %B4
+  %I = insertelement <4 x float> <float 0.25, float 0.25, float 0.25, float 0.25>, float 0.5, i64 %B5
+  store <4 x float> %I, ptr %p
+  ret void
+}


        


More information about the llvm-commits mailing list