[llvm] [InstCombine] Optimistically allow multiple shufflevector uses in foldOpPhi (PR #114278)
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 8 17:21:17 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)
----------------
MatzeB wrote:
I am still working on the feedback from above.
https://github.com/llvm/llvm-project/pull/114278
More information about the llvm-commits
mailing list