aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-01-06 16:56:34 +0100
committerNikita Popov <npopov@redhat.com>2023-01-06 17:06:25 +0100
commit7f0de9573f758f5f9108795850337a5acbd17eef (patch)
tree26354687e5097971661384501d08664de539b975 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
parentf9a0d045ca35b96e36e5a637d3338005d39ca09a (diff)
downloadllvm-7f0de9573f758f5f9108795850337a5acbd17eef.zip
llvm-7f0de9573f758f5f9108795850337a5acbd17eef.tar.gz
llvm-7f0de9573f758f5f9108795850337a5acbd17eef.tar.bz2
[Dominator] Add findNearestCommonDominator() for Instructions (NFC)
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.cpp9
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;
}