aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-01 06:11:53 +0000
committerChris Lattner <sabre@nondot.org>2009-11-01 06:11:53 +0000
commitb2710041fbed34ae888a6fed4172aea92bced1b5 (patch)
tree50d3cafef4ad8bc95ca5fbb0e3141525eab1c2c3
parent882029269e0cf4b497993b8e9a754429ef035fac (diff)
teach ipsccp and ipconstprop that a blockaddress doesn't 'take the address' of a function
in a way that should prevent ip constprop. This allows clang/test/CodeGen/indirect-goto.c to pass with the new indirect goto lowering. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85709 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/IPConstantPropagation.cpp3
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp6
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp
index d9b2e30631..023e642e64 100644
--- a/lib/Transforms/IPO/IPConstantPropagation.cpp
+++ b/lib/Transforms/IPO/IPConstantPropagation.cpp
@@ -86,6 +86,9 @@ bool IPCP::PropagateConstantsIntoArguments(Function &F) {
unsigned NumNonconstant = 0;
for (Value::use_iterator UI = F.use_begin(), E = F.use_end(); UI != E; ++UI) {
+ // Ignore blockaddress uses.
+ if (isa<BlockAddress>(*UI)) continue;
+
// Used by a non-instruction, or not the callee of a function, do not
// transform.
if (!isa<CallInst>(*UI) && !isa<InvokeInst>(*UI))
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 4e5fae8a04..a348e20907 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -1680,12 +1680,14 @@ static bool AddressIsTaken(GlobalValue *GV) {
return true; // Storing addr of GV.
} else if (isa<InvokeInst>(*UI) || isa<CallInst>(*UI)) {
// Make sure we are calling the function, not passing the address.
- CallSite CS = CallSite::get(cast<Instruction>(*UI));
- if (CS.hasArgument(GV))
+ if (UI.getOperandNo() != 0)
return true;
} else if (LoadInst *LI = dyn_cast<LoadInst>(*UI)) {
if (LI->isVolatile())
return true;
+ } else if (isa<BlockAddress>(*UI)) {
+ // blockaddress doesn't take the address of the function, it takes addr
+ // of label.
} else {
return true;
}