diff options
author | Nikita Popov <npopov@redhat.com> | 2023-01-06 16:56:34 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-01-10 12:16:31 +0100 |
commit | 094ccee2c89e9fa12a3439f5561f9472f98654e5 (patch) | |
tree | efc89cbd6ce4494127cbfecb0df6f3aefd6b541e /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | |
parent | 1ee4a93b15bb5dee7a1045fd035e1a286bb5d162 (diff) | |
download | llvm-094ccee2c89e9fa12a3439f5561f9472f98654e5.zip llvm-094ccee2c89e9fa12a3439f5561f9472f98654e5.tar.gz llvm-094ccee2c89e9fa12a3439f5561f9472f98654e5.tar.bz2 |
Reapply [Dominators] Add findNearestCommonDominator() for Instructions (NFC)
Reapply with checks for instructions in unreachable blocks. A test
case for this was added in 1ee4a93b15bb.
-----
This is a recurring pattern: We want to find the nearest common
dominator (instruction) for two instructions, but currently only
provide an API for the nearest common dominator of two basic blocks.
Add an overload that accepts and return instructions.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index a7fe065..4e83d2f 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -106,13 +106,8 @@ static Instruction *findCommonDominator(ArrayRef<Instruction *> Instructions, DominatorTree &DT) { Instruction *CommonDom = nullptr; for (auto *Insn : Instructions) - 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(); + CommonDom = + CommonDom ? DT.findNearestCommonDominator(CommonDom, Insn) : Insn; assert(CommonDom && "Common dominator not found?"); return CommonDom; } |