[llvm] e817029 - [DSE] Preserve address space
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 27 11:27:38 PDT 2021
Author: Nikita Popov
Date: 2021-06-27T20:26:00+02:00
New Revision: e81702912e6247c3adeb7e0c8416d6251d3b452a
URL: https://github.com/llvm/llvm-project/commit/e81702912e6247c3adeb7e0c8416d6251d3b452a
DIFF: https://github.com/llvm/llvm-project/commit/e81702912e6247c3adeb7e0c8416d6251d3b452a.diff
LOG: [DSE] Preserve address space
Preserve address space when inserting i8* cast.
Added:
Modified:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/OverwriteStoreBegin.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 5d45c20c22e5..358c5b831c5c 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -642,8 +642,10 @@ static bool tryToShorten(Instruction *EarlierWrite, int64_t &EarlierStart,
EarlierIntrinsic->setDestAlignment(PrefAlign);
if (!IsOverwriteEnd) {
- Type *Int8PtrTy = Type::getInt8PtrTy(EarlierIntrinsic->getContext());
Value *OrigDest = EarlierIntrinsic->getRawDest();
+ Type *Int8PtrTy =
+ Type::getInt8PtrTy(EarlierIntrinsic->getContext(),
+ OrigDest->getType()->getPointerAddressSpace());
Value *Dest = OrigDest;
if (OrigDest->getType() != Int8PtrTy)
Dest = CastInst::CreatePointerCast(OrigDest, Int8PtrTy, "", EarlierWrite);
diff --git a/llvm/test/Transforms/DeadStoreElimination/OverwriteStoreBegin.ll b/llvm/test/Transforms/DeadStoreElimination/OverwriteStoreBegin.ll
index 47bdd6132236..1cd4683a2d06 100644
--- a/llvm/test/Transforms/DeadStoreElimination/OverwriteStoreBegin.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/OverwriteStoreBegin.ll
@@ -61,6 +61,26 @@ entry:
ret void
}
+define void @write4to7_addrspace(i32 addrspace(1)* nocapture %p) {
+; CHECK-LABEL: @write4to7_addrspace(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[ARRAYIDX0:%.*]] = getelementptr inbounds i32, i32 addrspace(1)* [[P:%.*]], i64 1
+; CHECK-NEXT: [[P3:%.*]] = bitcast i32 addrspace(1)* [[ARRAYIDX0]] to i8 addrspace(1)*
+; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i8, i8 addrspace(1)* [[P3]], i64 4
+; CHECK-NEXT: call void @llvm.memset.p1i8.i64(i8 addrspace(1)* align 4 [[TMP0]], i8 0, i64 24, i1 false)
+; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, i32 addrspace(1)* [[P]], i64 1
+; CHECK-NEXT: store i32 1, i32 addrspace(1)* [[ARRAYIDX1]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ %arrayidx0 = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 1
+ %p3 = bitcast i32 addrspace(1)* %arrayidx0 to i8 addrspace(1)*
+ call void @llvm.memset.p1i8.i64(i8 addrspace(1)* align 4 %p3, i8 0, i64 28, i1 false)
+ %arrayidx1 = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 1
+ store i32 1, i32 addrspace(1)* %arrayidx1, align 4
+ ret void
+}
+
define void @write4to7_atomic(i32* nocapture %p) {
; CHECK-LABEL: @write4to7_atomic(
; CHECK-NEXT: entry:
@@ -433,6 +453,7 @@ entry:
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
declare void @llvm.memset.p0i32.i64(i32* nocapture, i8, i64, i1) nounwind
declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1) nounwind
+declare void @llvm.memset.p1i8.i64(i8 addrspace(1)* nocapture, i8, i64, i1) nounwind
declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* nocapture, i8, i64, i32) nounwind
define void @ow_begin_align1(i8* nocapture %p) {
More information about the llvm-commits
mailing list