[llvm] 2d77b0c - [Attributor] Ignore BlockAddress users in call site traversal

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 23:25:04 PDT 2019


Author: Johannes Doerfert
Date: 2019-11-02T01:23:18-05:00
New Revision: 2d77b0cad008eee612e3845769d8b08455a2176c

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

LOG: [Attributor] Ignore BlockAddress users in call site traversal

BlockAddress users will not "call" the function so they do not qualify
as call sites in the first place. When we delete a function with
BlockAddress users we need to first remove the body so they are properly
discarded.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/Attributor.cpp
    llvm/test/Transforms/FunctionAttrs/liveness.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 5082aa26dba3..29dc80ae591f 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -4658,6 +4658,9 @@ bool Attributor::checkForAllCallSites(
                         << Fn.getName()
                         << " has non call site use " << *U.get() << " in "
                         << *U.getUser() << "\n");
+      // BlockAddress users are allowed.
+      if (isa<BlockAddress>(U.getUser()))
+        continue;
       return false;
     }
 
@@ -5072,6 +5075,7 @@ ChangeStatus Attributor::run(Module &M) {
 
         STATS_TRACK(AAIsDead, Function);
         ToBeDeletedFunctions.insert(F);
+        F->deleteBody();
         F->replaceAllUsesWith(UndefValue::get(F->getType()));
         F->eraseFromParent();
         InternalFns[u] = nullptr;

diff  --git a/llvm/test/Transforms/FunctionAttrs/liveness.ll b/llvm/test/Transforms/FunctionAttrs/liveness.ll
index eef674b53eca..3b8705a5a506 100644
--- a/llvm/test/Transforms/FunctionAttrs/liveness.ll
+++ b/llvm/test/Transforms/FunctionAttrs/liveness.ll
@@ -2,6 +2,9 @@
 ; RUN: opt -attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=6 -S < %s | FileCheck %s
 ; UTC_ARGS: --turn off
 
+; CHECK: @dead_with_blockaddress_users.l = constant [2 x i8*] [i8* inttoptr (i32 1 to i8*), i8* inttoptr (i32 1 to i8*)]
+ at dead_with_blockaddress_users.l = constant [2 x i8*] [i8* blockaddress(@dead_with_blockaddress_users, %lab0), i8* blockaddress(@dead_with_blockaddress_users, %end)]
+
 declare void @no_return_call() nofree noreturn nounwind readnone
 
 declare void @normal_call() readnone
@@ -830,3 +833,25 @@ define i32 @switch_default_caller() {
   ret i32 %call2
 }
 ; UTC_ARGS: --turn off
+
+; Allow blockaddress users
+; CHECK-NOT @dead_with_blockaddress_users
+define internal void @dead_with_blockaddress_users(i32* nocapture %pc) nounwind readonly {
+entry:
+  br label %indirectgoto
+
+lab0:                                             ; preds = %indirectgoto
+  %indvar.next = add i32 %indvar, 1               ; <i32> [#uses=1]
+  br label %indirectgoto
+
+end:                                              ; preds = %indirectgoto
+  ret void
+
+indirectgoto:                                     ; preds = %lab0, %entry
+  %indvar = phi i32 [ %indvar.next, %lab0 ], [ 0, %entry ] ; <i32> [#uses=2]
+  %pc.addr.0 = getelementptr i32, i32* %pc, i32 %indvar ; <i32*> [#uses=1]
+  %tmp1.pn = load i32, i32* %pc.addr.0                 ; <i32> [#uses=1]
+  %indirect.goto.dest.in = getelementptr inbounds [2 x i8*], [2 x i8*]* @dead_with_blockaddress_users.l, i32 0, i32 %tmp1.pn ; <i8**> [#uses=1]
+  %indirect.goto.dest = load i8*, i8** %indirect.goto.dest.in ; <i8*> [#uses=1]
+  indirectbr i8* %indirect.goto.dest, [label %lab0, label %end]
+}


        


More information about the llvm-commits mailing list