[llvm] [VectorCombine] New folding pattern for extract/binop/shuffle chains (PR #145232)
Rajveer Singh Bharadwaj via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 5 02:54:40 PDT 2025
================
@@ -2988,6 +2989,241 @@ bool VectorCombine::foldShuffleFromReductions(Instruction &I) {
return foldSelectShuffle(*Shuffle, true);
}
+bool VectorCombine::foldShuffleChainsToReduce(Instruction &I) {
+ auto *EEI = dyn_cast<ExtractElementInst>(&I);
+ if (!EEI)
+ return false;
+
+ std::queue<Value *> InstWorklist;
+ InstructionCost OrigCost = 0;
+
+ Value *InitEEV = nullptr;
+
+ unsigned int CommonCallOp = 0;
+ Instruction::BinaryOps CommonBinOp = Instruction::BinaryOpsEnd;
+
+ bool IsFirstCallOrBinInst = true;
+ bool ShouldBeCallOrBinInst = true;
+
+ SmallVector<Value *, 3> PrevVecV(3, nullptr);
----------------
Rajveer100 wrote:
Yeah, documentation was the last thing left to add for this fold pattern. Since you asked, `PrevVecV` is used to store the last two instructions which are used either singly for shuffle vector or for binary operations. Specifically, `0` and `1` would be the ones that keep changing as we go up, whereas `2` is the one we get from extract operation.
These help differentiate between them in case they are mixed up.
https://github.com/llvm/llvm-project/pull/145232
More information about the llvm-commits
mailing list