From 2d77b0cad008eee612e3845769d8b08455a2176c Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Fri, 1 Nov 2019 22:35:18 -0500 Subject: [PATCH] [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. --- llvm/lib/Transforms/IPO/Attributor.cpp | 4 ++++ llvm/test/Transforms/FunctionAttrs/liveness.ll | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 5082aa2..29dc80a 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(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 eef674b..3b8705a 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*)] +@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 ; [#uses=1] + br label %indirectgoto + +end: ; preds = %indirectgoto + ret void + +indirectgoto: ; preds = %lab0, %entry + %indvar = phi i32 [ %indvar.next, %lab0 ], [ 0, %entry ] ; [#uses=2] + %pc.addr.0 = getelementptr i32, i32* %pc, i32 %indvar ; [#uses=1] + %tmp1.pn = load i32, i32* %pc.addr.0 ; [#uses=1] + %indirect.goto.dest.in = getelementptr inbounds [2 x i8*], [2 x i8*]* @dead_with_blockaddress_users.l, i32 0, i32 %tmp1.pn ; [#uses=1] + %indirect.goto.dest = load i8*, i8** %indirect.goto.dest.in ; [#uses=1] + indirectbr i8* %indirect.goto.dest, [label %lab0, label %end] +} -- 2.7.4