llvm.org GIT mirror llvm / 1522ce9
fix PR7876: If ipsccp decides that a function's address is taken before it rewrites the code, we need to use that in the post-rewrite pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110962 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
2 changed file(s) with 43 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
17481748 bool IPSCCP::runOnModule(Module &M) {
17491749 SCCPSolver Solver(getAnalysisIfAvailable());
17501750
1751 // AddressTakenFunctions - This set keeps track of the address-taken functions
1752 // that are in the input. As IPSCCP runs through and simplifies code,
1753 // functions that were address taken can end up losing their
1754 // address-taken-ness. Because of this, we keep track of their addresses from
1755 // the first pass so we can use them for the later simplification pass.
1756 SmallPtrSet AddressTakenFunctions;
1757
17511758 // Loop over all functions, marking arguments to those with their addresses
17521759 // taken or that are external as overdefined.
17531760 //
17631770 // If this function only has direct calls that we can see, we can track its
17641771 // arguments and return value aggressively, and can assume it is not called
17651772 // unless we see evidence to the contrary.
1766 if (F->hasLocalLinkage() && !AddressIsTaken(F)) {
1767 Solver.AddArgumentTrackedFunction(F);
1768 continue;
1773 if (F->hasLocalLinkage()) {
1774 if (AddressIsTaken(F))
1775 AddressTakenFunctions.insert(F);
1776 else {
1777 Solver.AddArgumentTrackedFunction(F);
1778 continue;
1779 }
17691780 }
17701781
17711782 // Assume the function is called.
19501961 continue;
19511962
19521963 // We can only do this if we know that nothing else can call the function.
1953 if (!F->hasLocalLinkage() || AddressIsTaken(F))
1964 if (!F->hasLocalLinkage() || AddressTakenFunctions.count(F))
19541965 continue;
19551966
19561967 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
0 ; RUN: opt %s -ipsccp -S | FileCheck %s
1 ; PR7876
2 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
3 target triple = "x86_64-apple-darwin10.0.0"
4
5 define internal i32 @foo() nounwind noinline ssp {
6 entry:
7 ret i32 0
8 ; CHECK: @foo
9 ; CHECK: entry:
10 ; CHECK: ret i32 0
11 }
12
13 declare i32 @bar()
14
15 define internal i32 @test(i32 %c) nounwind noinline ssp {
16 bb:
17 %tmp1 = icmp ne i32 %c, 0 ; [#uses=1]
18 %tmp2 = select i1 %tmp1, i32 ()* @foo, i32 ()* @bar ; [#uses=1]
19 %tmp3 = tail call i32 %tmp2() nounwind ; [#uses=1]
20 ret i32 %tmp3
21 }
22
23 define i32 @main() nounwind ssp {
24 bb:
25 %tmp = tail call i32 @test(i32 1) ; [#uses=1]
26 ret i32 %tmp
27 }