Skip to content

Commit 1f47990

Browse files
committed
[DSE] Use alias analysis to identify no-op stores
1 parent b900379 commit 1f47990

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,9 @@ struct DSEState {
21162116
return true;
21172117

21182118
if (auto *LoadI = dyn_cast<LoadInst>(Store->getOperand(0))) {
2119-
if (LoadI->getPointerOperand() == Store->getOperand(1)) {
2119+
if (LoadI->getPointerOperand() == Store->getOperand(1) ||
2120+
AA.isMustAlias(MemoryLocation::get(LoadI),
2121+
MemoryLocation::get(Store))) {
21202122
// Get the defining access for the load.
21212123
auto *LoadAccess = MSSA.getMemoryAccess(LoadI)->getDefiningAccess();
21222124
// Fast path: the defining accesses are the same.

llvm/test/Transforms/DeadStoreElimination/noop-stores.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,3 +1152,14 @@ if.else:
11521152
end:
11531153
ret void
11541154
}
1155+
1156+
define i32 @test_use_alias_analysis(ptr %Q) {
1157+
; CHECK-LABEL: @test_use_alias_analysis(
1158+
; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[Q:%.*]], align 4
1159+
; CHECK-NEXT: ret i32 [[A]]
1160+
;
1161+
%a = load i32, ptr %Q
1162+
%Q2 = addrspacecast ptr %Q to ptr addrspace(5)
1163+
store i32 %a, ptr addrspace(5) %Q2
1164+
ret i32 %a
1165+
}

0 commit comments

Comments
 (0)