[llvm] [SLP] Check the Operands of Copyable elements as well in getBestOperand() (PR #182443)
Ryan Buchner via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 19 23:03:32 PST 2026
================
@@ -2996,16 +2990,33 @@ class slpvectorizer::BoUpSLP {
case ReorderingMode::Load:
case ReorderingMode::Opcode: {
bool LeftToRight = Lane > LastLane;
- Value *OpLeft = (LeftToRight) ? OpLastLane : Op;
- Value *OpRight = (LeftToRight) ? Op : OpLastLane;
- int Score = getLookAheadScore(OpLeft, OpRight, MainAltOps, Lane,
- OpIdx, Idx, IsUsed, UsedLanes);
- if (Score > static_cast<int>(BestOp.Score) ||
- (Score > 0 && Score == static_cast<int>(BestOp.Score) &&
- Idx == OpIdx)) {
- BestOp.Idx = Idx;
- BestOp.Score = Score;
- BestScoresPerLanes[std::make_pair(OpIdx, Lane)] = Score;
+ auto ScoreLoadOrOpcode = [&](Value *Op, Value *OpLastLane) -> void {
+ Value *OpLeft = (LeftToRight) ? OpLastLane : Op;
+ Value *OpRight = (LeftToRight) ? Op : OpLastLane;
+ int Score = getLookAheadScore(OpLeft, OpRight, MainAltOps, Lane,
+ OpIdx, Idx, IsUsed, UsedLanes);
+ if (Score > static_cast<int>(BestOp.Score) ||
+ (Score > 0 && Score == static_cast<int>(BestOp.Score) &&
+ Idx == OpIdx)) {
+ BestOp.Idx = Idx;
+ BestOp.Score = Score;
+ BestScoresPerLanes[std::make_pair(OpIdx, Lane)] = Score;
+ }
+ };
+ ScoreLoadOrOpcode(Op, OpLastLane);
+ // If copyable, check against the operands of the copyable op
+ if (S.isCopyableElement(VL[Lane]) &&
+ !S.isCopyableElement(VL[LastLane])) {
+ if (Instruction *I = dyn_cast<Instruction>(Op)) {
+ if (Instruction::isBinaryOp(I->getOpcode())) {
----------------
bababuck wrote:
I can't think of a realistic situation where we would be interested in this for a non-binary operation. I think in practice the main cases this would apply to are when the copyable elements are not valid alternate opcodes (i.e. `!isValidForAlternation() { !isIntDivRem(); }`)
https://github.com/llvm/llvm-project/pull/182443
More information about the llvm-commits
mailing list