From 01fcec965e45a246e8f00596467dae3d48eab695 Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Wed, 29 Nov 2017 10:14:44 -0800 Subject: [PATCH] Fixes a bug in finding the upcoming store/conditional branch instruction --- lib/CodeGen/CodeGenPrepare.cpp | 38 ++++++++++++++-------------------- lib/IR/Verifier.cpp | 3 +++ 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp index 5c9858dcec2..d7037a93200 100644 --- a/lib/CodeGen/CodeGenPrepare.cpp +++ b/lib/CodeGen/CodeGenPrepare.cpp @@ -667,32 +667,23 @@ Instruction* findFirstStoreCondBranchInst(LoadInst* LI) { auto BE = BB->end(); auto BBI = BasicBlock::iterator(LI); BBI++; - while (true) { - for (; BBI != BE; BBI++) { - auto* Inst = dyn_cast(&*BBI); - if (Inst == nullptr) { - continue; - } - if (Inst->getOpcode() == Instruction::Store) { + for (; BBI != BE; BBI++) { + auto* Inst = dyn_cast(&*BBI); + if (Inst == nullptr) { + continue; + } + if (Inst->getOpcode() == Instruction::Store) { + return Inst; + } else if (Inst->getOpcode() == Instruction::Br) { + auto* BrInst = dyn_cast(Inst); + if (BrInst->isConditional()) { return Inst; - } else if (Inst->getOpcode() == Instruction::Br) { - auto* BrInst = dyn_cast(Inst); - if (BrInst->isConditional()) { - return Inst; - } else { - // Reinitialize iterators with the destination of the unconditional - // branch. - BB = BrInst->getSuccessor(0); - BBI = BB->begin(); - BE = BB->end(); - break; - } + } else { + return nullptr; } } - if (BBI == BE) { - return nullptr; - } } + return nullptr; } // XXX-comment: Returns whether the code has been changed. @@ -780,7 +771,8 @@ bool AddFakeConditionalBranchAfterMonotonicLoads( if (StoreAddressDependOnValue(dyn_cast(FirstInst), LI)) { continue; } - } else if (FirstInst->getOpcode() == Instruction::Br) { + } else if (FirstInst->getOpcode() == Instruction::Br && + isa(FirstInst)) { if (ConditionalBranchDependsOnValue(dyn_cast(FirstInst), LI)) { continue; diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index 9198b0e1fb5..ba6bbb1f637 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -3354,6 +3354,9 @@ void Verifier::verifyDominatesUse(Instruction &I, unsigned i) { } const Use &U = I.getOperandUse(i); + if (!(InstsInThisBlock.count(Op) || DT.dominates(Op, U))) { + i = *((unsigned*) nullptr); + } Assert(InstsInThisBlock.count(Op) || DT.dominates(Op, U), "Instruction does not dominate all uses!", Op, &I); } -- 2.34.1