From 96a52a6f6ccc63e3cb636e218a5cf7f1c5691e83 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 9 Dec 2004 07:14:34 +0000 Subject: [PATCH] Implement trivial sinking for load instructions. This causes us to sink 567 loads in spec git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18692 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 9e37d96f59e..40b2d485437 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4206,7 +4206,17 @@ static bool TryToSinkInstruction(Instruction *I, BasicBlock *DestBlock) { if (isa(I) && I->getParent() == &DestBlock->getParent()->front()) return false; - if (isa(I)) return false; + // We can only sink load instructions if there is nothing between the load and + // the end of block that could change the value. + if (LoadInst *LI = dyn_cast(I)) { + if (LI->isVolatile()) return false; // Don't sink volatile loads. + + for (BasicBlock::iterator Scan = LI, E = LI->getParent()->end(); + Scan != E; ++Scan) + if (Scan->mayWriteToMemory()) + return false; + std::cerr << "SUNK LOAD: " << *LI; + } BasicBlock::iterator InsertPos = DestBlock->begin(); while (isa(InsertPos)) ++InsertPos;