[llvm] 3e8c436 - [Attributor] Visit droppable uses in AAIsDead

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 16:21:41 PDT 2022


Author: Johannes Doerfert
Date: 2022-04-05T18:20:45-05:00
New Revision: 3e8c4366e223ebe6005316930f382efb251f8434

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

LOG: [Attributor] Visit droppable uses in AAIsDead

If we ignore droppable users everything only used in llvm.assume (among
other things) is going to be deleted as dead. This is not helpful.
Instead we want to only delete things we actually don't need anymore. A
follow up will deal with loads in a smarter way.

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/IPO/Attributor.h
    llvm/lib/Transforms/IPO/Attributor.cpp
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp
    llvm/test/Transforms/Attributor/nonnull.ll
    llvm/test/Transforms/Attributor/value-simplify-assume.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 83779bcb36339..9b77ba538b06c 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1695,6 +1695,7 @@ struct Attributor {
                        const AbstractAttribute &QueryingAA, const Value &V,
                        bool CheckBBLivenessOnly = false,
                        DepClassTy LivenessDepClass = DepClassTy::OPTIONAL,
+                       bool IgnoreDroppableUses = true,
                        function_ref<bool(const Use &OldU, const Use &NewU)>
                            EquivalentUseCB = nullptr);
 

diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index c32440cc0dec8..d2c965308cb6c 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1261,6 +1261,7 @@ bool Attributor::checkForAllUses(
     function_ref<bool(const Use &, bool &)> Pred,
     const AbstractAttribute &QueryingAA, const Value &V,
     bool CheckBBLivenessOnly, DepClassTy LivenessDepClass,
+    bool IgnoreDroppableUses,
     function_ref<bool(const Use &OldU, const Use &NewU)> EquivalentUseCB) {
 
   // Check the trivial case first as it catches void values.
@@ -1301,7 +1302,7 @@ bool Attributor::checkForAllUses(
       LLVM_DEBUG(dbgs() << "[Attributor] Dead use, skip!\n");
       continue;
     }
-    if (U->getUser()->isDroppable()) {
+    if (IgnoreDroppableUses && U->getUser()->isDroppable()) {
       LLVM_DEBUG(dbgs() << "[Attributor] Droppable user, skip!\n");
       continue;
     }

diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index e9e48acf2bc58..fc9794632e19d 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1511,7 +1511,7 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
     };
     if (!A.checkForAllUses(UsePred, *this, AssociatedValue,
                            /* CheckBBLivenessOnly */ true, DepClassTy::OPTIONAL,
-                           EquivalentUseCB))
+                           /* IgnoreDroppableUses */ true, EquivalentUseCB))
       return indicatePessimisticFixpoint();
 
     LLVM_DEBUG({
@@ -3530,7 +3530,8 @@ struct AAIsDeadValueImpl : public AAIsDead {
     // without going through N update cycles. This is not required for
     // correctness.
     return A.checkForAllUses(UsePred, *this, V, /* CheckBBLivenessOnly */ false,
-                             DepClassTy::REQUIRED);
+                             DepClassTy::REQUIRED,
+                             /* IgnoreDroppableUses */ false);
   }
 
   /// Determine if \p I is assumed to be side-effect free.

diff  --git a/llvm/test/Transforms/Attributor/nonnull.ll b/llvm/test/Transforms/Attributor/nonnull.ll
index bd9e82974f61e..b4f8eaa598a5a 100644
--- a/llvm/test/Transforms/Attributor/nonnull.ll
+++ b/llvm/test/Transforms/Attributor/nonnull.ll
@@ -318,14 +318,16 @@ define i8* @test10(i8* %a, i64 %n) {
 ; NOT_CGSCC_NPM: Function Attrs: inaccessiblememonly nofree norecurse nosync nounwind willreturn
 ; NOT_CGSCC_NPM-LABEL: define {{[^@]+}}@test10
 ; NOT_CGSCC_NPM-SAME: (i8* nofree readnone "no-capture-maybe-returned" [[A:%.*]], i64 [[N:%.*]]) #[[ATTR2]] {
-; NOT_CGSCC_NPM-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR13]]
+; NOT_CGSCC_NPM-NEXT:    [[CMP:%.*]] = icmp ne i64 [[N]], 0
+; NOT_CGSCC_NPM-NEXT:    call void @llvm.assume(i1 noundef [[CMP]]) #[[ATTR13]]
 ; NOT_CGSCC_NPM-NEXT:    [[B:%.*]] = getelementptr inbounds i8, i8* [[A]], i64 [[N]]
 ; NOT_CGSCC_NPM-NEXT:    ret i8* [[B]]
 ;
 ; IS__CGSCC_NPM: Function Attrs: inaccessiblememonly nofree norecurse nosync nounwind willreturn
 ; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@test10
 ; IS__CGSCC_NPM-SAME: (i8* nofree readnone "no-capture-maybe-returned" [[A:%.*]], i64 [[N:%.*]]) #[[ATTR2]] {
-; IS__CGSCC_NPM-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR12]]
+; IS__CGSCC_NPM-NEXT:    [[CMP:%.*]] = icmp ne i64 [[N]], 0
+; IS__CGSCC_NPM-NEXT:    call void @llvm.assume(i1 noundef [[CMP]]) #[[ATTR12]]
 ; IS__CGSCC_NPM-NEXT:    [[B:%.*]] = getelementptr inbounds i8, i8* [[A]], i64 [[N]]
 ; IS__CGSCC_NPM-NEXT:    ret i8* [[B]]
 ;

diff  --git a/llvm/test/Transforms/Attributor/value-simplify-assume.ll b/llvm/test/Transforms/Attributor/value-simplify-assume.ll
index 5d6a7fdd27e27..69dcc515ab0b3 100644
--- a/llvm/test/Transforms/Attributor/value-simplify-assume.ll
+++ b/llvm/test/Transforms/Attributor/value-simplify-assume.ll
@@ -242,6 +242,8 @@ define void @assume_1b_nr(i1 %arg, i1 %cond) norecurse {
 ; CHECK: Function Attrs: inaccessiblememonly nofree norecurse nosync nounwind willreturn
 ; CHECK-LABEL: define {{[^@]+}}@assume_1b_nr
 ; CHECK-SAME: (i1 [[ARG:%.*]], i1 [[COND:%.*]]) #[[ATTR3]] {
+; CHECK-NEXT:    [[STACK:%.*]] = alloca i1, align 1
+; CHECK-NEXT:    store i1 [[ARG]], i1* [[STACK]], align 1
 ; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[ARG]]) #[[ATTR4]]
 ; CHECK-NEXT:    br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
 ; CHECK:       t:
@@ -303,13 +305,18 @@ define void @assume_2b_nr(i1 %arg, i1 %cond) norecurse {
 ; CHECK: Function Attrs: inaccessiblememonly nofree norecurse nosync nounwind willreturn
 ; CHECK-LABEL: define {{[^@]+}}@assume_2b_nr
 ; CHECK-SAME: (i1 [[ARG:%.*]], i1 [[COND:%.*]]) #[[ATTR3]] {
+; CHECK-NEXT:    [[STACK:%.*]] = alloca i1, align 1
+; CHECK-NEXT:    store i1 [[ARG]], i1* [[STACK]], align 1
 ; CHECK-NEXT:    br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
 ; CHECK:       t:
+; CHECK-NEXT:    store i1 true, i1* [[STACK]], align 1
 ; CHECK-NEXT:    br label [[M:%.*]]
 ; CHECK:       f:
+; CHECK-NEXT:    store i1 false, i1* [[STACK]], align 1
 ; CHECK-NEXT:    br label [[M]]
 ; CHECK:       m:
-; CHECK-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; CHECK-NEXT:    [[L:%.*]] = load i1, i1* [[STACK]], align 1
+; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[L]]) #[[ATTR4]]
 ; CHECK-NEXT:    ret void
 ;
   %stack = alloca i1
@@ -375,7 +382,8 @@ define i1 @assume_4_nr(i1 %arg, i1 %cond) norecurse {
 ; CHECK-NEXT:    store i1 false, i1* [[STACK]], align 1
 ; CHECK-NEXT:    br label [[M]]
 ; CHECK:       m:
-; CHECK-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; CHECK-NEXT:    [[L:%.*]] = load i1, i1* [[STACK]], align 1
+; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[L]]) #[[ATTR4]]
 ; CHECK-NEXT:    [[R:%.*]] = call i1 @readI1p(i1* noalias nocapture nofree noundef nonnull readonly dereferenceable(1) [[STACK]]) #[[ATTR5]]
 ; CHECK-NEXT:    ret i1 [[R]]
 ;
@@ -405,14 +413,17 @@ define i1 @assume_5_nr(i1 %arg, i1 %cond) norecurse {
 ; IS________OPM-NEXT:    br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
 ; IS________OPM:       t:
 ; IS________OPM-NEXT:    store i1 true, i1* [[STACK]], align 1
-; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; IS________OPM-NEXT:    [[L2:%.*]] = load i1, i1* [[STACK]], align 1
+; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef [[L2]]) #[[ATTR4]]
 ; IS________OPM-NEXT:    br label [[M:%.*]]
 ; IS________OPM:       f:
 ; IS________OPM-NEXT:    store i1 false, i1* [[STACK]], align 1
-; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; IS________OPM-NEXT:    [[L3:%.*]] = load i1, i1* [[STACK]], align 1
+; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef [[L3]]) #[[ATTR4]]
 ; IS________OPM-NEXT:    br label [[M]]
 ; IS________OPM:       m:
-; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; IS________OPM-NEXT:    [[L4:%.*]] = load i1, i1* [[STACK]], align 1
+; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef [[L4]]) #[[ATTR4]]
 ; IS________OPM-NEXT:    [[R:%.*]] = call i1 @readI1p(i1* noalias nocapture nofree noundef nonnull readonly dereferenceable(1) [[STACK]]) #[[ATTR5]]
 ; IS________OPM-NEXT:    ret i1 [[R]]
 ;
@@ -432,7 +443,8 @@ define i1 @assume_5_nr(i1 %arg, i1 %cond) norecurse {
 ; IS________NPM-NEXT:    call void @llvm.assume(i1 noundef false) #[[ATTR4]]
 ; IS________NPM-NEXT:    br label [[M]]
 ; IS________NPM:       m:
-; IS________NPM-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; IS________NPM-NEXT:    [[L4:%.*]] = load i1, i1* [[STACK]], align 1
+; IS________NPM-NEXT:    call void @llvm.assume(i1 noundef [[L4]]) #[[ATTR4]]
 ; IS________NPM-NEXT:    [[R:%.*]] = call i1 @readI1p(i1* noalias nocapture nofree noundef nonnull readonly dereferenceable(1) [[STACK]]) #[[ATTR5]]
 ; IS________NPM-NEXT:    ret i1 [[R]]
 ;
@@ -472,10 +484,12 @@ define i1 @assume_5c_nr(i1 %cond) norecurse {
 ; IS________OPM-NEXT:    br label [[M:%.*]]
 ; IS________OPM:       f:
 ; IS________OPM-NEXT:    store i1 false, i1* [[STACK]], align 1
-; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; IS________OPM-NEXT:    [[L3:%.*]] = load i1, i1* [[STACK]], align 1
+; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef [[L3]]) #[[ATTR4]]
 ; IS________OPM-NEXT:    br label [[M]]
 ; IS________OPM:       m:
-; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; IS________OPM-NEXT:    [[L4:%.*]] = load i1, i1* [[STACK]], align 1
+; IS________OPM-NEXT:    call void @llvm.assume(i1 noundef [[L4]]) #[[ATTR4]]
 ; IS________OPM-NEXT:    [[R:%.*]] = call i1 @readI1p(i1* noalias nocapture nofree noundef nonnull readonly dereferenceable(1) [[STACK]]) #[[ATTR5]]
 ; IS________OPM-NEXT:    ret i1 [[R]]
 ;
@@ -495,7 +509,8 @@ define i1 @assume_5c_nr(i1 %cond) norecurse {
 ; IS________NPM-NEXT:    call void @llvm.assume(i1 noundef false) #[[ATTR4]]
 ; IS________NPM-NEXT:    br label [[M]]
 ; IS________NPM:       m:
-; IS________NPM-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; IS________NPM-NEXT:    [[L4:%.*]] = load i1, i1* [[STACK]], align 1
+; IS________NPM-NEXT:    call void @llvm.assume(i1 noundef [[L4]]) #[[ATTR4]]
 ; IS________NPM-NEXT:    [[R:%.*]] = call i1 @readI1p(i1* noalias nocapture nofree noundef nonnull readonly dereferenceable(1) [[STACK]]) #[[ATTR5]]
 ; IS________NPM-NEXT:    ret i1 [[R]]
 ;
@@ -733,6 +748,8 @@ define void @assume_1b(i1 %arg, i1 %cond) {
 ; CHECK: Function Attrs: inaccessiblememonly nofree norecurse nosync nounwind willreturn
 ; CHECK-LABEL: define {{[^@]+}}@assume_1b
 ; CHECK-SAME: (i1 [[ARG:%.*]], i1 [[COND:%.*]]) #[[ATTR3]] {
+; CHECK-NEXT:    [[STACK:%.*]] = alloca i1, align 1
+; CHECK-NEXT:    store i1 [[ARG]], i1* [[STACK]], align 1
 ; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[ARG]]) #[[ATTR4]]
 ; CHECK-NEXT:    br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
 ; CHECK:       t:
@@ -794,13 +811,18 @@ define void @assume_2b(i1 %arg, i1 %cond) {
 ; CHECK: Function Attrs: inaccessiblememonly nofree norecurse nosync nounwind willreturn
 ; CHECK-LABEL: define {{[^@]+}}@assume_2b
 ; CHECK-SAME: (i1 [[ARG:%.*]], i1 [[COND:%.*]]) #[[ATTR3]] {
+; CHECK-NEXT:    [[STACK:%.*]] = alloca i1, align 1
+; CHECK-NEXT:    store i1 [[ARG]], i1* [[STACK]], align 1
 ; CHECK-NEXT:    br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
 ; CHECK:       t:
+; CHECK-NEXT:    store i1 true, i1* [[STACK]], align 1
 ; CHECK-NEXT:    br label [[M:%.*]]
 ; CHECK:       f:
+; CHECK-NEXT:    store i1 false, i1* [[STACK]], align 1
 ; CHECK-NEXT:    br label [[M]]
 ; CHECK:       m:
-; CHECK-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; CHECK-NEXT:    [[L:%.*]] = load i1, i1* [[STACK]], align 1
+; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[L]]) #[[ATTR4]]
 ; CHECK-NEXT:    ret void
 ;
   %stack = alloca i1
@@ -866,7 +888,8 @@ define i1 @assume_4(i1 %arg, i1 %cond) {
 ; CHECK-NEXT:    store i1 false, i1* [[STACK]], align 1
 ; CHECK-NEXT:    br label [[M]]
 ; CHECK:       m:
-; CHECK-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; CHECK-NEXT:    [[L:%.*]] = load i1, i1* [[STACK]], align 1
+; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[L]]) #[[ATTR4]]
 ; CHECK-NEXT:    [[R:%.*]] = call i1 @readI1p(i1* noalias nocapture nofree noundef nonnull readonly dereferenceable(1) [[STACK]]) #[[ATTR5]]
 ; CHECK-NEXT:    ret i1 [[R]]
 ;
@@ -896,14 +919,17 @@ define i1 @assume_5(i1 %arg, i1 %cond) {
 ; CHECK-NEXT:    br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
 ; CHECK:       t:
 ; CHECK-NEXT:    store i1 true, i1* [[STACK]], align 1
-; CHECK-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; CHECK-NEXT:    [[L2:%.*]] = load i1, i1* [[STACK]], align 1
+; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[L2]]) #[[ATTR4]]
 ; CHECK-NEXT:    br label [[M:%.*]]
 ; CHECK:       f:
 ; CHECK-NEXT:    store i1 false, i1* [[STACK]], align 1
-; CHECK-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; CHECK-NEXT:    [[L3:%.*]] = load i1, i1* [[STACK]], align 1
+; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[L3]]) #[[ATTR4]]
 ; CHECK-NEXT:    br label [[M]]
 ; CHECK:       m:
-; CHECK-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; CHECK-NEXT:    [[L4:%.*]] = load i1, i1* [[STACK]], align 1
+; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[L4]]) #[[ATTR4]]
 ; CHECK-NEXT:    [[R:%.*]] = call i1 @readI1p(i1* noalias nocapture nofree noundef nonnull readonly dereferenceable(1) [[STACK]]) #[[ATTR5]]
 ; CHECK-NEXT:    ret i1 [[R]]
 ;
@@ -943,10 +969,12 @@ define i1 @assume_5c(i1 %cond) {
 ; CHECK-NEXT:    br label [[M:%.*]]
 ; CHECK:       f:
 ; CHECK-NEXT:    store i1 false, i1* [[STACK]], align 1
-; CHECK-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; CHECK-NEXT:    [[L3:%.*]] = load i1, i1* [[STACK]], align 1
+; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[L3]]) #[[ATTR4]]
 ; CHECK-NEXT:    br label [[M]]
 ; CHECK:       m:
-; CHECK-NEXT:    call void @llvm.assume(i1 noundef true) #[[ATTR4]]
+; CHECK-NEXT:    [[L4:%.*]] = load i1, i1* [[STACK]], align 1
+; CHECK-NEXT:    call void @llvm.assume(i1 noundef [[L4]]) #[[ATTR4]]
 ; CHECK-NEXT:    [[R:%.*]] = call i1 @readI1p(i1* noalias nocapture nofree noundef nonnull readonly dereferenceable(1) [[STACK]]) #[[ATTR5]]
 ; CHECK-NEXT:    ret i1 [[R]]
 ;


        


More information about the llvm-commits mailing list