diff options
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index 4e83d2f..a7fe065 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -106,8 +106,13 @@ static Instruction *findCommonDominator(ArrayRef<Instruction *> Instructions, DominatorTree &DT) { Instruction *CommonDom = nullptr; for (auto *Insn : Instructions) - CommonDom = - CommonDom ? DT.findNearestCommonDominator(CommonDom, Insn) : Insn; + if (!CommonDom || DT.dominates(Insn, CommonDom)) + CommonDom = Insn; + else if (!DT.dominates(CommonDom, Insn)) + // If there is no dominance relation, use common dominator. + CommonDom = + DT.findNearestCommonDominator(CommonDom->getParent(), + Insn->getParent())->getTerminator(); assert(CommonDom && "Common dominator not found?"); return CommonDom; } |