[llvm] [VectorCombine][AMDGPU] Narrow Phi of Shuffles. (PR #140188)
    Simon Pilgrim via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Fri May 16 02:19:56 PDT 2025
    
    
  
================
@@ -3483,6 +3484,109 @@ bool VectorCombine::foldInterleaveIntrinsics(Instruction &I) {
   return true;
 }
 
+// Attempt to narrow a phi of shufflevector instructions where the two incoming
+// values have the same operands but different masks. If the two shuffle masks
+// are offsets of one another we can use one branch to rotate the incoming
+// vector and perform one larger shuffle after the phi.
+bool VectorCombine::shrinkPhiOfShuffles(Instruction &I) {
+  auto *Phi = dyn_cast<PHINode>(&I);
+  if (!Phi || Phi->getNumIncomingValues() != 2u)
+    return false;
+
+  auto *Shuf0 = dyn_cast<ShuffleVectorInst>(Phi->getOperand(0u));
+  auto *Shuf1 = dyn_cast<ShuffleVectorInst>(Phi->getOperand(1u));
+  if (!Shuf0 || !Shuf1)
+    return false;
+
+  if (!Shuf0->hasOneUse() && !Shuf1->hasOneUse())
+    return false;
----------------
RKSimon wrote:
you can almost certainly make this clearer with PatternMatch
https://github.com/llvm/llvm-project/pull/140188
    
    
More information about the llvm-commits
mailing list