summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-11 19:34:32 +0000
committerChris Lattner <sabre@nondot.org>2008-01-11 19:34:32 +0000
commit4a70261f006ab0f42df5e7a13e01d5d179d265c6 (patch)
tree44d31822ad8c43ac61ff8806b606ef43c60e04de /llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
parent4062a625e5d48c60ee346cada8f98a01663275e7 (diff)
downloadbcm5719-llvm-4a70261f006ab0f42df5e7a13e01d5d179d265c6.tar.gz
bcm5719-llvm-4a70261f006ab0f42df5e7a13e01d5d179d265c6.zip
a byval argument is guaranteed to be valid to load.
llvm-svn: 45877
Diffstat (limited to 'llvm/lib/Transforms/IPO/ArgumentPromotion.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/ArgumentPromotion.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index 42a7067f23b..1c739adcea3 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -193,7 +193,15 @@ static bool AllCalleesPassInValidPointerForArgument(Argument *Arg) {
bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg, bool isByVal) const {
// We can only promote this argument if all of the uses are loads, or are GEP
// instructions (with constant indices) that are subsequently loaded.
- bool HasLoadInEntryBlock = false;
+
+ // We can also only promote the load if we can guarantee that it will happen.
+ // Promoting a load causes the load to be unconditionally executed in the
+ // caller, so we can't turn a conditional load into an unconditional load in
+ // general.
+ bool SafeToUnconditionallyLoad = false;
+ if (isByVal) // ByVal arguments are always safe to load from.
+ SafeToUnconditionallyLoad = true;
+
BasicBlock *EntryBlock = Arg->getParent()->begin();
SmallVector<LoadInst*, 16> Loads;
std::vector<SmallVector<ConstantInt*, 8> > GEPIndices;
@@ -202,7 +210,10 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg, bool isByVal) const {
if (LoadInst *LI = dyn_cast<LoadInst>(*UI)) {
if (LI->isVolatile()) return false; // Don't hack volatile loads
Loads.push_back(LI);
- HasLoadInEntryBlock |= LI->getParent() == EntryBlock;
+
+ // If this load occurs in the entry block, then the pointer is
+ // unconditionally loaded.
+ SafeToUnconditionallyLoad |= LI->getParent() == EntryBlock;
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(*UI)) {
if (GEP->use_empty()) {
// Dead GEP's cause trouble later. Just remove them if we run into
@@ -225,7 +236,10 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg, bool isByVal) const {
if (LoadInst *LI = dyn_cast<LoadInst>(*UI)) {
if (LI->isVolatile()) return false; // Don't hack volatile loads
Loads.push_back(LI);
- HasLoadInEntryBlock |= LI->getParent() == EntryBlock;
+
+ // If this load occurs in the entry block, then the pointer is
+ // unconditionally loaded.
+ SafeToUnconditionallyLoad |= LI->getParent() == EntryBlock;
} else {
return false;
}
@@ -257,7 +271,8 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg, bool isByVal) const {
// of the pointer in the entry block of the function) or if we can prove that
// all pointers passed in are always to legal locations (for example, no null
// pointers are passed in, no pointers to free'd memory, etc).
- if (!HasLoadInEntryBlock && !AllCalleesPassInValidPointerForArgument(Arg))
+ if (!SafeToUnconditionallyLoad &&
+ !AllCalleesPassInValidPointerForArgument(Arg))
return false; // Cannot prove that this is safe!!
// Okay, now we know that the argument is only used by load instructions and
OpenPOWER on IntegriCloud