[llvm] a325622 - [DSE] Allow attribute differences in redundant store elimination (#125190)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 07:10:52 PST 2025


Author: Nikita Popov
Date: 2025-01-31T16:10:48+01:00
New Revision: a325622be523e977e0c4bae81ea8e4c6916cdb21

URL: https://github.com/llvm/llvm-project/commit/a325622be523e977e0c4bae81ea8e4c6916cdb21
DIFF: https://github.com/llvm/llvm-project/commit/a325622be523e977e0c4bae81ea8e4c6916cdb21.diff

LOG: [DSE] Allow attribute differences in redundant store elimination (#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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
    llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll

Removed: 
    


################################################################################
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 
diff erences 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_
diff erent_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_
diff erent_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