summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-01 22:30:07 +0000
committerChris Lattner <sabre@nondot.org>2007-02-01 22:30:07 +0000
commitc904205d286018ec0a109d010d16a190d8d4ffce (patch)
tree429d3ffef98e8fd564a20d9ff2f228cf38738c5a /llvm/lib/Transforms/Scalar/InstructionCombining.cpp
parent9a677c585c04201a0adf3a996e0010fe4eed70a2 (diff)
downloadbcm5719-llvm-c904205d286018ec0a109d010d16a190d8d4ffce.tar.gz
bcm5719-llvm-c904205d286018ec0a109d010d16a190d8d4ffce.zip
Fix Transforms/InstCombine/2007-02-01-LoadSinkAlloca.ll, a serious code
pessimization where instcombine can sink a load (good for code size) that prevents an alloca from being promoted by mem2reg (bad for everything). llvm-svn: 33771
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index aec61ab0767..9fbcdc182db 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -7464,12 +7464,36 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
/// of the block that defines it. This means that it must be obvious the value
/// of the load is not changed from the point of the load to the end of the
/// block it is in.
+///
+/// Finally, it is safe, but not profitable, to sink a load targetting a
+/// non-address-taken alloca. Doing so will cause us to not promote the alloca
+/// to a register.
static bool isSafeToSinkLoad(LoadInst *L) {
BasicBlock::iterator BBI = L, E = L->getParent()->end();
for (++BBI; BBI != E; ++BBI)
if (BBI->mayWriteToMemory())
return false;
+
+ // Check for non-address taken alloca. If not address-taken already, it isn't
+ // profitable to do this xform.
+ if (AllocaInst *AI = dyn_cast<AllocaInst>(L->getOperand(0))) {
+ bool isAddressTaken = false;
+ for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end();
+ UI != E; ++UI) {
+ if (isa<LoadInst>(UI)) continue;
+ if (StoreInst *SI = dyn_cast<StoreInst>(*UI)) {
+ // If storing TO the alloca, then the address isn't taken.
+ if (SI->getOperand(1) == AI) continue;
+ }
+ isAddressTaken = true;
+ break;
+ }
+
+ if (!isAddressTaken)
+ return false;
+ }
+
return true;
}
OpenPOWER on IntegriCloud