diff options
author | Dehao Chen <dehao@google.com> | 2016-10-17 19:28:44 +0000 |
---|---|---|
committer | Dehao Chen <dehao@google.com> | 2016-10-17 19:28:44 +0000 |
commit | 018a3afa99573586646e36d6e3e20e59975466bb (patch) | |
tree | 109e2b84ff4f34004848f20829e3a016b6c937fe /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | d6d2bafacc8a2fb1056a24bf52ae7044564f9fe8 (diff) | |
download | bcm5719-llvm-018a3afa99573586646e36d6e3e20e59975466bb.tar.gz bcm5719-llvm-018a3afa99573586646e36d6e3e20e59975466bb.zip |
Ignore debug info when making optimization decisions in SimplifyCFG.
Summary: Debug info should *not* affect code generation. This patch properly handles debug info to make sure the generated code are the same with or without debug info.
Reviewers: davidxl, mzolotukhin, jmolloy
Subscribers: aprantl, llvm-commits
Differential Revision: https://reviews.llvm.org/D25286
llvm-svn: 284415
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index c7c66fd9d74..ec5db1e5744 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1485,8 +1485,14 @@ static bool sinkLastInstruction(ArrayRef<BasicBlock*> Blocks) { // canSinkLastInstruction returning true guarantees that every block has at // least one non-terminator instruction. SmallVector<Instruction*,4> Insts; - for (auto *BB : Blocks) - Insts.push_back(BB->getTerminator()->getPrevNode()); + for (auto *BB : Blocks) { + Instruction *I = BB->getTerminator(); + do { + I = I->getPrevNode(); + } while (isa<DbgInfoIntrinsic>(I) && I != &BB->front()); + if (!isa<DbgInfoIntrinsic>(I)) + Insts.push_back(I); + } // The only checking we need to do now is that all users of all instructions // are the same PHI node. canSinkLastInstruction should have checked this but @@ -1584,15 +1590,15 @@ namespace { Fail = false; Insts.clear(); for (auto *BB : Blocks) { - if (Instruction *Terminator = BB->getTerminator()) { - if (Instruction *LastNonTerminator = Terminator->getPrevNode()) { - Insts.push_back(LastNonTerminator); - continue; - } + Instruction *Inst = BB->getTerminator(); + for (Inst = Inst->getPrevNode(); Inst && isa<DbgInfoIntrinsic>(Inst);) + Inst = Inst->getPrevNode(); + if (!Inst) { + // Block wasn't big enough. + Fail = true; + return; } - // Block wasn't big enough. - Fail = true; - return; + Insts.push_back(Inst); } } @@ -1604,7 +1610,8 @@ namespace { if (Fail) return; for (auto *&Inst : Insts) { - Inst = Inst->getPrevNode(); + for (Inst = Inst->getPrevNode(); Inst && isa<DbgInfoIntrinsic>(Inst);) + Inst = Inst->getPrevNode(); // Already at beginning of block. if (!Inst) { Fail = true; |