[RISCV] Ignore interleaved accesses with non-default address spaces (#139698)
This fixes a crash introduced in
https://github.com/llvm/llvm-project/pull/137045#issuecomment-2872208568
where we don't have overloaded pointer types for segmented load/store
intrinsics.
This should be temporary until #139634 lands and overloads the pointer
type for these
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 0f93bd9..ecd2813 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -23417,6 +23417,11 @@
MVT ContainerVT = VT.getSimpleVT();
+ // The intrinsics are not (yet) overloaded on pointer type and can only handle
+ // the default address space.
+ if (AddrSpace)
+ return false;
+
if (auto *FVTy = dyn_cast<FixedVectorType>(VTy)) {
if (!Subtarget.useRVVForFixedLengthVectors())
return false;
@@ -23426,11 +23431,6 @@
return false;
ContainerVT = getContainerForFixedLengthVector(VT.getSimpleVT());
- } else {
- // The intrinsics for scalable vectors are not overloaded on pointer type
- // and can only handle the default address space.
- if (AddrSpace)
- return false;
}
// Need to make sure that EMUL * NFIELDS ≤ 8
diff --git a/llvm/test/Transforms/InterleavedAccess/RISCV/addrspace.ll b/llvm/test/Transforms/InterleavedAccess/RISCV/addrspace.ll
new file mode 100644
index 0000000..d971892
--- /dev/null
+++ b/llvm/test/Transforms/InterleavedAccess/RISCV/addrspace.ll
@@ -0,0 +1,34 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -mtriple=riscv64 -mattr=+v -p interleaved-access -S | FileCheck %s
+
+; Ensure we don't crash with non-zero address spaces.
+
+define void @load_factor2(ptr addrspace(1) %ptr) {
+; CHECK-LABEL: define void @load_factor2(
+; CHECK-SAME: ptr addrspace(1) [[PTR:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[INTERLEAVED_VEC:%.*]] = load <16 x i32>, ptr addrspace(1) [[PTR]], align 64
+; CHECK-NEXT: [[V0:%.*]] = shufflevector <16 x i32> [[INTERLEAVED_VEC]], <16 x i32> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>
+; CHECK-NEXT: [[V1:%.*]] = shufflevector <16 x i32> [[INTERLEAVED_VEC]], <16 x i32> poison, <8 x i32> <i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15>
+; CHECK-NEXT: ret void
+;
+ %interleaved.vec = load <16 x i32>, ptr addrspace(1) %ptr
+ %v0 = shufflevector <16 x i32> %interleaved.vec, <16 x i32> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>
+ %v1 = shufflevector <16 x i32> %interleaved.vec, <16 x i32> poison, <8 x i32> <i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15>
+ ret void
+}
+
+define void @load_factor2_vscale(ptr addrspace(1) %ptr) {
+; CHECK-LABEL: define void @load_factor2_vscale(
+; CHECK-SAME: ptr addrspace(1) [[PTR:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: [[INTERLEAVED_VEC:%.*]] = load <vscale x 16 x i32>, ptr addrspace(1) [[PTR]], align 64
+; CHECK-NEXT: [[V:%.*]] = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.vector.deinterleave2.nxv16i32(<vscale x 16 x i32> [[INTERLEAVED_VEC]])
+; CHECK-NEXT: [[T0:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[V]], 0
+; CHECK-NEXT: [[T1:%.*]] = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } [[V]], 1
+; CHECK-NEXT: ret void
+;
+ %interleaved.vec = load <vscale x 16 x i32>, ptr addrspace(1) %ptr
+ %v = call { <vscale x 8 x i32>, <vscale x 8 x i32> } @llvm.vector.deinterleave2.nxv16i32(<vscale x 16 x i32> %interleaved.vec)
+ %t0 = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } %v, 0
+ %t1 = extractvalue { <vscale x 8 x i32>, <vscale x 8 x i32> } %v, 1
+ ret void
+}