[llvm] [InstCombine] Relax the conditons of fold of `ucmp`/`scmp` into phi by allowing the phi node to use the result of `ucmp`/`scmp` more than once (PR #109593)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 00:30:58 PDT 2024
================
@@ -1868,18 +1868,25 @@ Instruction *InstCombinerImpl::foldOpIntoPhi(Instruction &I, PHINode *PN) {
// Clone the instruction that uses the phi node and move it into the incoming
// BB because we know that the next iteration of InstCombine will simplify it.
+ SmallDenseMap<BasicBlock *, Instruction *> Clones;
for (auto OpIndex : OpsToMoveUseToIncomingBB) {
Value *Op = PN->getIncomingValue(OpIndex);
BasicBlock *OpBB = PN->getIncomingBlock(OpIndex);
- Instruction *Clone = I.clone();
- for (Use &U : Clone->operands()) {
- if (U == PN)
- U = Op;
- else
- U = U->DoPHITranslation(PN->getParent(), OpBB);
+ auto CloneIt = Clones.find(OpBB);
----------------
nikic wrote:
I'd probably do `Instruction *Clone = Clones.lookup(OpBB); if (!Clone)` here, rather than working on iterators.
https://github.com/llvm/llvm-project/pull/109593
More information about the llvm-commits
mailing list