[llvm] [SLP] NFC. Replace TreeEntry::setOperandsInOrder with VLOperands. (PR #113880)
Han-Kuan Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 21 01:59:25 PST 2024
================
@@ -8497,20 +8488,13 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
ReuseShuffleIndices);
LLVM_DEBUG(dbgs() << "SLP: added a vector of un/bin op.\n");
+ VLOperands Ops(VL, *this);
// Sort operands of the instructions so that each side is more likely to
// have the same opcode.
- if (isa<BinaryOperator>(VL0) && isCommutative(VL0)) {
- ValueList Left, Right;
- reorderInputsAccordingToOpcode(VL, Left, Right, *this);
- TE->setOperand(0, Left);
- TE->setOperand(1, Right);
- buildTree_rec(Left, Depth + 1, {TE, 0});
- buildTree_rec(Right, Depth + 1, {TE, 1});
- return;
- }
-
- TE->setOperandsInOrder();
- for (unsigned I : seq<unsigned>(0, VL0->getNumOperands()))
+ if (isa<BinaryOperator>(VL0) && isCommutative(VL0))
+ Ops.reorder();
----------------
HanKuanChen wrote:
I don't think it is a good idea. Current `reorder` usage is
```
if (cast<CmpInst>(VL0)->isCommutative()) {
// Commutative predicate - collect + sort operands of the instructions
// so that each side is more likely to have the same opcode.
assert(P0 == CmpInst::getSwappedPredicate(P0) &&
"Commutative Predicate mismatch");
Ops.reorder();
```
```
if (isa<BinaryOperator>(VL0) && isCommutative(VL0))
Ops.reorder();
```
```
if (isCommutative(VL0))
Ops.reorder();
```
```
auto *CI = dyn_cast<CmpInst>(VL0);
if (isa<BinaryOperator>(VL0) || CI) {
if (!CI || all_of(VL, [](Value *V) {
return cast<CmpInst>(V)->isCommutative();
})) {
Ops.reorder();
```
They use `reorder` when VL0 is commutative. But the last one determine the condition in another way.
Move `reorder` into other place does not make the code neater (the last one still exist).
https://github.com/llvm/llvm-project/pull/113880
More information about the llvm-commits
mailing list