[PATCH] D143886: [DAG] Handle build_vector with all undefs in reduceBuildVecTruncToBitCast

Pierre van Houtryve via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 13 23:52:03 PST 2023


Pierre-vh updated this revision to Diff 497217.
Pierre-vh added a comment.

Reduce test, move test elsewhere (as it doesn't have a bitcast anymore)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143886/new/

https://reviews.llvm.org/D143886

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/AMDGPU/undef-build-vector.ll


Index: llvm/test/CodeGen/AMDGPU/undef-build-vector.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/undef-build-vector.ll
@@ -0,0 +1,17 @@
+; RUN: llc -march=amdgcn < %s | FileCheck %s
+; RUN: llc -march=amdgcn -mcpu=tonga < %s | FileCheck %s
+; RUN: llc -march=amdgcn -mcpu=gfx900 < %s | FileCheck %s
+
+; Checks that we don't crash when code produces a build_vector with two undef operands.
+
+; CHECK: {{^}}buildvector_undefs:
+define amdgpu_kernel void @buildvector_undefs(<2 x i16> %in) {
+entry:
+  %i0 = call <16 x i16> @llvm.vector.insert.v16i16.v2i16(<16 x i16> poison, <2 x i16> %in, i64 0)
+  %i1 = call <16 x i16> @llvm.vector.insert.v16i16.v2i16(<16 x i16> %i0, <2 x i16> zeroinitializer, i64 2)
+  store <16 x i16> %i1, ptr addrspace(1) null, align 32
+  ret void
+}
+
+declare <2 x i16> @llvm.vector.extract.v2i16.v16i16(<16 x i16>, i64 immarg)
+declare <16 x i16> @llvm.vector.insert.v16i16.v2i16(<16 x i16>, <2 x i16>, i64 immarg)
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -21492,7 +21492,7 @@
   }
 
   // Only cast if the size is the same
-  if (Src.getValueType().getSizeInBits() != VT.getSizeInBits())
+  if (!Src || Src.getValueType().getSizeInBits() != VT.getSizeInBits())
     return SDValue();
 
   return DAG.getBitcast(VT, Src);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143886.497217.patch
Type: text/x-patch
Size: 1503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230214/02653587/attachment.bin>


More information about the llvm-commits mailing list