-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[DSE] Use alias analysis to identify no-op stores #122610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[DSE] Use alias analysis to identify no-op stores #122610
Conversation
|
@llvm/pr-subscribers-llvm-transforms Author: Alex MacLean (AlexMaclean) ChangesFull diff: https://github.com/llvm/llvm-project/pull/122610.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index cae5b9c41a37f1..908b9110bd595d 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -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),
+ MemoryLocation::get(Store))) {
// Get the defining access for the load.
auto *LoadAccess = MSSA.getMemoryAccess(LoadI)->getDefiningAccess();
// Fast path: the defining accesses are the same.
diff --git a/llvm/test/Transforms/DeadStoreElimination/noop-stores.ll b/llvm/test/Transforms/DeadStoreElimination/noop-stores.ll
index 9fc20d76da5eb4..5bedc1ebe8281e 100644
--- a/llvm/test/Transforms/DeadStoreElimination/noop-stores.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/noop-stores.ll
@@ -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
+}
|
nikic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fhahn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm seems quite high for no changes. @AlexMaclean do you have any data on how many additional stores can be removed with this change on larger workloads?
| 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), |
There was a problem hiding this comment.
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?
No description provided.