[llvm] [InstCombine] Optimistically allow multiple shufflevector uses in foldOpPhi (PR #114278)
David Peixotto via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 8 16:08:34 PST 2024
================
@@ -1773,17 +1773,31 @@ Instruction *InstCombinerImpl::foldOpIntoPhi(Instruction &I, PHINode *PN) {
if (NumPHIValues == 0)
return nullptr;
- // We normally only transform phis with a single use. However, if a PHI has
- // multiple uses and they are all the same operation, we can fold *all* of the
- // uses into the PHI.
+ // We normally only transform phis with a single use.
+ bool AllUsesIdentical = false;
+ bool MultipleShuffleVectorUses = false;
if (!PN->hasOneUse()) {
- // Walk the use list for the instruction, comparing them to I.
+ // Exceptions:
+ // - All uses are identical.
+ // - All uses are shufflevector instructions that fully simplify; this
+ // helps interleave -> phi -> 2x de-interleave+de patterns.
+ MultipleShuffleVectorUses = isa<ShuffleVectorInst>(I);
+ AllUsesIdentical = true;
+ unsigned NumUses = 0;
for (User *U : PN->users()) {
+ ++NumUses;
Instruction *UI = cast<Instruction>(U);
- if (UI != &I && !I.isIdenticalTo(UI))
+ if (UI == &I)
+ continue;
+
+ if (!I.isIdenticalTo(UI))
+ AllUsesIdentical = false;
+ // Only inspect first 4 uses to avoid quadratic complexity.
+ if (!isa<ShuffleVectorInst>(UI) || NumUses > 4)
----------------
dmpots wrote:
Is there something special about `shufflevector` that we would only want this to apply to that type of instruction? It seems like the other checks are generic and as long as the users all simplify it should be ok?
https://github.com/llvm/llvm-project/pull/114278
More information about the llvm-commits
mailing list