[llvm] dc29901 - [AMDGPU] PromoteAlloca: handle out-of-bounds GEP for shufflevector (#139700)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 21 06:28:33 PDT 2025
Author: Robert Imschweiler
Date: 2025-05-21T15:28:30+02:00
New Revision: dc29901efb18880679b965538ae8bc3f6dd5ecd8
URL: https://github.com/llvm/llvm-project/commit/dc29901efb18880679b965538ae8bc3f6dd5ecd8
DIFF: https://github.com/llvm/llvm-project/commit/dc29901efb18880679b965538ae8bc3f6dd5ecd8.diff
LOG: [AMDGPU] PromoteAlloca: handle out-of-bounds GEP for shufflevector (#139700)
This LLVM defect was identified via the AMD Fuzzing project.
---------
Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
Added:
llvm/test/CodeGen/AMDGPU/promote-alloca-shufflevector.ll
Modified:
llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index 933ee6ceeaf4a..517d05f6514d5 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -666,7 +666,9 @@ static Value *promoteAllocaUserToVector(
SmallVector<int> Mask;
for (unsigned Idx = 0; Idx < VectorTy->getNumElements(); ++Idx) {
if (Idx >= DestBegin && Idx < DestBegin + NumCopied) {
- Mask.push_back(SrcBegin++);
+ Mask.push_back(SrcBegin < VectorTy->getNumElements()
+ ? SrcBegin++
+ : PoisonMaskElem);
} else {
Mask.push_back(Idx);
}
diff --git a/llvm/test/CodeGen/AMDGPU/promote-alloca-shufflevector.ll b/llvm/test/CodeGen/AMDGPU/promote-alloca-shufflevector.ll
new file mode 100644
index 0000000000000..c16d0e8381ecd
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/promote-alloca-shufflevector.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -mtriple amdgcn -passes=amdgpu-promote-alloca-to-vector -S < %s | FileCheck %s
+
+; Skip promote-alloca in case of an index which is known to be out of bounds.
+
+define amdgpu_kernel void @out_of_bounds() {
+; CHECK-LABEL: define amdgpu_kernel void @out_of_bounds() {
+; CHECK-NEXT: [[PTR:%.*]] = freeze <4 x float> poison
+; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[PTR]], <4 x float> poison, <4 x i32> <i32 poison, i32 poison, i32 2, i32 3>
+; CHECK-NEXT: ret void
+;
+ %ptr = alloca [4 x float], align 4, addrspace(5)
+ %elem_ptr = getelementptr [4 x float], ptr addrspace(5) %ptr, i32 0, i32 42
+ call void @llvm.memcpy.p5.p5.i32(ptr addrspace(5) %ptr, ptr addrspace(5) %elem_ptr, i32 8, i1 false)
+ ret void
+}
+
+define amdgpu_kernel void @memcpy_partially_out_of_bounds() {
+; CHECK-LABEL: define amdgpu_kernel void @memcpy_partially_out_of_bounds() {
+; CHECK-NEXT: [[PTR:%.*]] = freeze <3 x float> poison
+; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <3 x float> [[PTR]], <3 x float> poison, <3 x i32> <i32 2, i32 poison, i32 2>
+; CHECK-NEXT: ret void
+;
+ %ptr = alloca [3 x float], align 4, addrspace(5)
+ %elem_ptr = getelementptr [3 x float], ptr addrspace(5) %ptr, i32 0, i32 2
+ call void @llvm.memcpy.p5.p5.i32(ptr addrspace(5) %ptr, ptr addrspace(5) %elem_ptr, i32 8, i1 false)
+ ret void
+}
+
+define amdgpu_kernel void @in_bounds() {
+; CHECK-LABEL: define amdgpu_kernel void @in_bounds() {
+; CHECK-NEXT: [[PTR:%.*]] = freeze <4 x float> poison
+; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[PTR]], <4 x float> poison, <4 x i32> <i32 2, i32 3, i32 2, i32 3>
+; CHECK-NEXT: ret void
+;
+ %ptr = alloca [4 x float], align 4, addrspace(5)
+ %elem_ptr = getelementptr [4 x float], ptr addrspace(5) %ptr, i32 0, i32 2
+ call void @llvm.memcpy.p5.p5.i32(ptr addrspace(5) %ptr, ptr addrspace(5) %elem_ptr, i32 8, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p5.p5.i32(ptr addrspace(5) writeonly captures(none), ptr addrspace(5) readonly captures(none), i32, i1 immarg) #0
+
+attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
More information about the llvm-commits
mailing list