[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:51:14 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: hanbeom (ParkHanbum)
<details>
<summary>Changes</summary>
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`.
---
Full diff: https://github.com/llvm/llvm-project/pull/79565.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (+4-3)
- (modified) llvm/test/Transforms/InstCombine/store.ll (+16)
``````````diff
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"}
``````````
</details>
https://github.com/llvm/llvm-project/pull/79565
More information about the llvm-commits
mailing list