[PATCH] D111885: [SelectionDAG] Fix illegal widening of scalable-vector loads

Fraser Cormack via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 15 06:50:55 PDT 2021


frasercrmck created this revision.
frasercrmck added reviewers: craig.topper, RKSimon, spatel.
Herald added subscribers: ecnelises, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
frasercrmck requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.

The process of widening simple vector loads attempts to use a load of a
wider vector type if the original load is sufficiently aligned to avoid
memory faults.

However this optimization is only legal when performed on fixed-length
vector types. For scalable vector types this is invalid (unless vscale
happens to be 1).

This patch does increase the likelihood of compiler crashes (from
`FindMemType` failing to find a suitable type) but this now better
matches how widening non-simple loads, insufficiently-aligned loads, and
scalable-vector stores are handled.

Patches will be introduced later by which loads and stores can be
widened on targets with support for masked or predicated operations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111885

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  llvm/test/CodeGen/RISCV/rvv/legalize-load-sdnode.ll
  llvm/test/CodeGen/RISCV/rvv/legalize-store-sdnode.ll


Index: llvm/test/CodeGen/RISCV/rvv/legalize-store-sdnode.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rvv/legalize-store-sdnode.ll
@@ -0,0 +1,16 @@
+; RUN: not --crash llc -mtriple=riscv32 -mattr=+m,+experimental-v,+experimental-zfh,+f,+d -verify-machineinstrs < %s
+; RUN: not --crash llc -mtriple=riscv64 -mattr=+m,+experimental-v,+experimental-zfh,+f,+d -verify-machineinstrs < %s
+
+; Check that we are able to legalize scalable-vector stores that require widening.
+
+; FIXME: LLVM can't yet widen scalable-vector stores.
+
+define void @store_nxv3i8(<vscale x 3 x i8> %val, <vscale x 3 x i8>* %ptr) {
+  store <vscale x 3 x i8> %val, <vscale x 3 x i8>* %ptr
+  ret void
+}
+
+define void @store_nxv7f64(<vscale x 7 x double> %val, <vscale x 7 x double>* %ptr) {
+  store <vscale x 7 x double> %val, <vscale x 7 x double>* %ptr
+  ret void
+}
Index: llvm/test/CodeGen/RISCV/rvv/legalize-load-sdnode.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rvv/legalize-load-sdnode.ll
@@ -0,0 +1,16 @@
+; RUN: not --crash llc -mtriple=riscv32 -mattr=+m,+experimental-v,+experimental-zfh,+f,+d -verify-machineinstrs < %s
+; RUN: not --crash llc -mtriple=riscv64 -mattr=+m,+experimental-v,+experimental-zfh,+f,+d -verify-machineinstrs < %s
+
+; Check that we are able to legalize scalable-vector loads that require widening.
+
+; FIXME: LLVM can't yet widen scalable-vector loads.
+
+define <vscale x 3 x i8> @load_nxv3i8(<vscale x 3 x i8>* %ptr) {
+  %v = load <vscale x 3 x i8>, <vscale x 3 x i8>* %ptr
+  ret <vscale x 3 x i8> %v
+}
+
+define <vscale x 5 x half> @load_nxv5f16(<vscale x 5 x half>* %ptr) {
+  %v = load <vscale x 5 x half>, <vscale x 5 x half>* %ptr
+  ret <vscale x 5 x half> %v
+}
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -5394,7 +5394,8 @@
   TypeSize WidthDiff = WidenWidth - LdWidth;
   // Allow wider loads if they are sufficiently aligned to avoid memory faults
   // and if the original load is simple.
-  unsigned LdAlign = (!LD->isSimple()) ? 0 : LD->getAlignment();
+  unsigned LdAlign =
+      (!LD->isSimple() || LdVT.isScalableVector()) ? 0 : LD->getAlignment();
 
   // Find the vector type that can load from.
   EVT NewVT = FindMemType(DAG, TLI, LdWidth.getKnownMinSize(), WidenVT, LdAlign,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111885.379986.patch
Type: text/x-patch
Size: 2560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211015/6b6b4487/attachment.bin>


More information about the llvm-commits mailing list