We can try to replace select with a Phi not in its parent block alone, but also in blocks of its arguments.
We benefit from it when select's argument is a Phi.
Details
Diff Detail
Event Timeline
Ideally we could consider all dominator chain, but this is too expensive. This is attempt to reduce the impact.
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | ||
---|---|---|
2518 | It seems quite likely that some of the parents (or all of them) are going to be the same. Might it make sense to deduplicate? // Collect likely candidates for placing the phi node. SmallPtrSet<BasicBlock *, 4> CandidateBlocks; CandidateBlocks.insert(Sel.getParent(); for (Value *V : Sel.operands()) if (auto *I = dyn_cast<Instruction>(V)) CandidateBlocks.insert(I->getParent()); for (BasicBlock *BB : CandidateBlocks) if (auto *PN = foldSelectToPhiImpl(Sel, BB, DT, Builder)) return PN; |
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | ||
---|---|---|
2518 | Agreed. |
Implemented deduplication (used SetVector to ensure that we have deterministic fold order).
llvm/test/Transforms/InstCombine/select.ll | ||
---|---|---|
2416 | I don't understand why this returns %B (and what the difference to the previous test is, for that matter). |
llvm/test/Transforms/InstCombine/select.ll | ||
---|---|---|
2416 | It actually returns %A, %B here is just a regex name. Seems that I miscopied it on revase, it was supposed to exertice scenario %sel = select i1 %cond, i32 %A, i32 %phi |
llvm/test/Transforms/InstCombine/select.ll | ||
---|---|---|
2416 | Fixed the test test_select_into_phi_not_idom_2 and var naming in it. It was supposed to show that we can replace Phi that is a false value of select (the previous test shows when it's a true value). |
It seems quite likely that some of the parents (or all of them) are going to be the same. Might it make sense to deduplicate?