[llvm] [DSE] Allow attribute differences in redundant store elimination (PR #125190)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 31 01:45:55 PST 2025
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/125190
When comparing the instructions, enable attribute intersection to allow differences in attributes.
Note that we don't actually have to intersect the attributes on the earlier instruction, because we're not RAUWing, so there's no chance that we make any values more poisonous.
>From 2372ed3f26868ee7af91f4523d603c1230be0e52 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Fri, 31 Jan 2025 10:41:53 +0100
Subject: [PATCH] [DSE] Allow attribute differences in redundant store
elimination
When comparing the instructions, enable attribute intersection to
allow differences in attributes.
Note that we don't actually have to intersect the attributes on
the earlier instruction, because we're not RAUWing, so there's
no chance that we make any values more poisonous.
---
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 4 +++-
.../DeadStoreElimination/stores-of-existing-values.ll | 2 --
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 13f3de07c3c44d..05b4f176bfc31c 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -2210,7 +2210,9 @@ struct DSEState {
Instruction *UpperInst = UpperDef->getMemoryInst();
auto IsRedundantStore = [&]() {
- if (DefInst->isIdenticalTo(UpperInst))
+ // We don't care about differences in call attributes here.
+ if (DefInst->isIdenticalToWhenDefined(UpperInst,
+ /*IntersectAttrs=*/true))
return true;
if (auto *MemSetI = dyn_cast<MemSetInst>(UpperInst)) {
if (auto *SI = dyn_cast<StoreInst>(DefInst)) {
diff --git a/llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll b/llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
index 193b42ca9e09a6..4f38027f172130 100644
--- a/llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
@@ -752,7 +752,6 @@ define void @memset_different_attributes_1(i1 %c, ptr %ptr) {
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[PTR:%.*]], i8 0, i64 20, i1 false)
; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[END:%.*]]
; CHECK: if:
-; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr dereferenceable(20) [[PTR]], i8 0, i64 20, i1 false)
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: ret void
@@ -773,7 +772,6 @@ define void @memset_different_attributes_2(i1 %c, ptr %ptr) {
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr dereferenceable(20) [[PTR:%.*]], i8 0, i64 20, i1 false)
; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[END:%.*]]
; CHECK: if:
-; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[PTR]], i8 0, i64 20, i1 false)
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: ret void
More information about the llvm-commits
mailing list