[llvm] 0a07343 - [AMDGPU] Fixed constexpr expansion to handle multiple uses
Stanislav Mekhanoshin via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 16 16:57:54 PDT 2021
Author: Stanislav Mekhanoshin
Date: 2021-06-16T16:57:41-07:00
New Revision: 0a07343e34fc84052e6cc54e55654412b0ed01f4
URL: https://github.com/llvm/llvm-project/commit/0a07343e34fc84052e6cc54e55654412b0ed01f4
DIFF: https://github.com/llvm/llvm-project/commit/0a07343e34fc84052e6cc54e55654412b0ed01f4.diff
LOG: [AMDGPU] Fixed constexpr expansion to handle multiple uses
Recently added convertConstantExprsToInstructions() does not handle
a case when a same ConstantExpr used multiple times in the same
instruction. A first use is replaced and the rest of the uses in the
instruction are replaced as well with the replaceUsesOfWith(). Then
function attempts to replace a constant already destroyed.
So far this interface is only used by the AMDGPU BE.
Differential Revision: https://reviews.llvm.org/D104425
Added:
Modified:
llvm/lib/IR/ReplaceConstant.cpp
llvm/test/CodeGen/AMDGPU/lower-kernel-lds-constexpr.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/ReplaceConstant.cpp b/llvm/lib/IR/ReplaceConstant.cpp
index 06dedb293d02d..9382f820a7f29 100644
--- a/llvm/lib/IR/ReplaceConstant.cpp
+++ b/llvm/lib/IR/ReplaceConstant.cpp
@@ -84,6 +84,7 @@ void convertConstantExprsToInstructions(
Instruction *I,
std::map<Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths,
SmallPtrSetImpl<Instruction *> *Insts) {
+ SmallPtrSet<ConstantExpr *, 8> Visited;
for (Use &U : I->operands()) {
// The operand U is either not a constant expression operand or the
// constant expression paths do not belong to U, ignore U.
@@ -102,7 +103,6 @@ void convertConstantExprsToInstructions(
// constant expressions along all paths to corresponding instructions.
auto *II = I;
auto &Paths = CEPaths[&U];
- SmallPtrSet<ConstantExpr *, 8> Visited;
for (auto &Path : Paths) {
for (auto *CE : Path) {
if (!Visited.insert(CE).second)
diff --git a/llvm/test/CodeGen/AMDGPU/lower-kernel-lds-constexpr.ll b/llvm/test/CodeGen/AMDGPU/lower-kernel-lds-constexpr.ll
index 99a7c2127a19c..402a75f958a44 100644
--- a/llvm/test/CodeGen/AMDGPU/lower-kernel-lds-constexpr.ll
+++ b/llvm/test/CodeGen/AMDGPU/lower-kernel-lds-constexpr.ll
@@ -9,6 +9,7 @@
; CHECK: %llvm.amdgcn.kernel.k2.lds.t = type { i32 }
; CHECK: %llvm.amdgcn.kernel.k3.lds.t = type { [32 x i8] }
; CHECK: %llvm.amdgcn.kernel.k4.lds.t = type { [2 x i8] }
+; CHECK: %llvm.amdgcn.kernel.k5.lds.t = type { [505 x i32] }
; Use constant from
diff erent kernels
;.
@@ -17,6 +18,7 @@
; CHECK: @llvm.amdgcn.kernel.k2.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k2.lds.t undef, align 4
; CHECK: @llvm.amdgcn.kernel.k3.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k3.lds.t undef, align 16
; CHECK: @llvm.amdgcn.kernel.k4.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k4.lds.t undef, align 2
+; CHECK: @llvm.amdgcn.kernel.k5.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k5.lds.t undef, align 16
;.
define amdgpu_kernel void @k0(i64 %x) {
; CHECK-LABEL: @k0(
@@ -97,3 +99,16 @@ define amdgpu_kernel void @k4(i64 %x) {
store i8 1, i8 addrspace(0)* %ptr, align 1
ret void
}
+
+ at lds.4 = internal unnamed_addr addrspace(3) global [505 x i32] undef, align 4
+
+; Multiple constexpr use in a same instruction.
+define amdgpu_kernel void @k5() {
+; CHECK-LABEL: @k5(
+; CHECK-NEXT: %1 = addrspacecast [505 x i32] addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.k5.lds.t, %llvm.amdgcn.kernel.k5.lds.t addrspace(3)* @llvm.amdgcn.kernel.k5.lds, i32 0, i32 0) to [505 x i32]*
+; CHECK-NEXT: %2 = getelementptr inbounds [505 x i32], [505 x i32]* %1, i64 0, i64 0
+; CHECK-NEXT: call void undef(i32* %2, i32* %2)
+;
+ call void undef(i32* getelementptr inbounds ([505 x i32], [505 x i32]* addrspacecast ([505 x i32] addrspace(3)* @lds.4 to [505 x i32]*), i64 0, i64 0), i32* getelementptr inbounds ([505 x i32], [505 x i32]* addrspacecast ([505 x i32] addrspace(3)* @lds.4 to [505 x i32]*), i64 0, i64 0))
+ ret void
+}
More information about the llvm-commits
mailing list