Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,9 @@ struct DSEState {
return true;

if (auto *LoadI = dyn_cast<LoadInst>(Store->getOperand(0))) {
if (LoadI->getPointerOperand() == Store->getOperand(1)) {
if (LoadI->getPointerOperand() == Store->getOperand(1) ||
AA.isMustAlias(MemoryLocation::get(LoadI),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming my understanding of the problem: checking that the address spaces are not equal is insufficient because address spaces may not be disjoint, correct?

MemoryLocation::get(Store))) {
// Get the defining access for the load.
auto *LoadAccess = MSSA.getMemoryAccess(LoadI)->getDefiningAccess();
// Fast path: the defining accesses are the same.
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Transforms/DeadStoreElimination/noop-stores.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1152,3 +1152,14 @@ if.else:
end:
ret void
}

define i32 @test_use_alias_analysis(ptr %Q) {
; CHECK-LABEL: @test_use_alias_analysis(
; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[Q:%.*]], align 4
; CHECK-NEXT: ret i32 [[A]]
;
%a = load i32, ptr %Q
%Q2 = addrspacecast ptr %Q to ptr addrspace(5)
store i32 %a, ptr addrspace(5) %Q2
ret i32 %a
}
Loading