[llvm] [InstCombine] Remove Store which has one-use AddrSpaceCastInst as Ptr (#68120) (PR #79565)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 26 01:50:45 PST 2024
https://github.com/ParkHanbum created https://github.com/llvm/llvm-project/pull/79565
If the `store` target is OneUse and the user is `AddrSpaceCastInst`, proper processing was not performed. Therefore, when processing `Alloca` in the second process, this storage space was deleted and a problem occurred.
This patch removes the `store` when the store target is OneUse and the user is `AddrSpaceCastInst`.
>From 1ff87fc20971705659ad2803502cae831bbe718b Mon Sep 17 00:00:00 2001
From: Hanbum Park <kese111 at gmail.com>
Date: Fri, 26 Jan 2024 18:30:47 +0900
Subject: [PATCH] [InstCombine] Remove Store which has one-use
AddrSpaceCastInst as Ptr (#68120)
If the `store` target is OneUse and the user is `AddrSpaceCastInst`,
proper processing was not performed. Therefore, when processing
`Alloca` in the second process, this storage space was deleted and
a problem occurred.
This patch removes the `store` when the store target is OneUse and
the user is `AddrSpaceCastInst`.
---
.../InstCombine/InstCombineLoadStoreAlloca.cpp | 7 ++++---
llvm/test/Transforms/InstCombine/store.ll | 16 ++++++++++++++++
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index bb2a77daa60a764..94a0d0cc4acc58a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1385,9 +1385,10 @@ Instruction *InstCombinerImpl::visitStoreInst(StoreInst &SI) {
if (Ptr->hasOneUse()) {
if (isa<AllocaInst>(Ptr))
return eraseInstFromFunction(SI);
- if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) {
- if (isa<AllocaInst>(GEP->getOperand(0))) {
- if (GEP->getOperand(0)->hasOneUse())
+ if (isa<GetElementPtrInst>(Ptr) || isa<AddrSpaceCastInst>(Ptr)) {
+ Instruction *PtrI = dyn_cast<Instruction>(Ptr);
+ if (isa<AllocaInst>(PtrI->getOperand(0))) {
+ if (PtrI->getOperand(0)->hasOneUse())
return eraseInstFromFunction(SI);
}
}
diff --git a/llvm/test/Transforms/InstCombine/store.ll b/llvm/test/Transforms/InstCombine/store.ll
index 673395464c85aaf..969d766a2d1e2bf 100644
--- a/llvm/test/Transforms/InstCombine/store.ll
+++ b/llvm/test/Transforms/InstCombine/store.ll
@@ -345,6 +345,22 @@ define void @store_to_readonly_noalias(ptr readonly noalias %0) {
ret void
}
+; if ptr which store to is addrspacecast, and its target is alloca. remove it.
+define void @src_store_oneuse_addrspaceast_alloca(ptr align 8 %arg) {
+; CHECK-LABEL: @src_store_oneuse_addrspaceast_alloca(
+; CHECK-NEXT: bb:
+; CHECK-NEXT: store ptr poison, ptr null, align 8
+; CHECK-NEXT: ret void
+;
+bb:
+ %i = alloca ptr, align 8, addrspace(5)
+ %i1 = addrspacecast ptr addrspace(5) %i to ptr
+ store ptr %arg, ptr %i1, align 8
+ %i2 = load ptr, ptr %i1, align 8
+ store ptr %i2, ptr null, align 8
+ ret void
+}
+
!0 = !{!4, !4, i64 0}
!1 = !{!"omnipotent char", !2}
!2 = !{!"Simple C/C++ TBAA"}
More information about the llvm-commits
mailing list