[PATCH] D147198: [WASM] Fix [pr61828](https://github.com/llvm/llvm-project/issues/61828)

Peter Rong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 29 22:13:35 PDT 2023


Peter created this revision.
Herald added subscribers: pmatos, asb, ctetreau, sunfish, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a project: All.
Peter requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

WebAssembly tries to cast a undef to CosntantSDNode during `LowerAccessVectorElement`.
This 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147198

Files:
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/test/CodeGen/WebAssembly/pr61828.ll


Index: llvm/test/CodeGen/WebAssembly/pr61828.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -196,7 +196,7 @@
 
     // Support splatting
     for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v4f32, MVT::v2i64,
-		   MVT::v2f64})
+                   MVT::v2f64})
       setOperationAction(ISD::SPLAT_VECTOR, T, Legal);
 
     // Custom lowering since wasm shifts must have a scalar shift amount
@@ -2240,7 +2240,7 @@
                                                     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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147198.509547.patch
Type: text/x-patch
Size: 1582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230330/937b6c51/attachment.bin>


More information about the llvm-commits mailing list