Skip to content

Commit 699e22a

Browse files
committed
[ISEL] Move trivial step_vector folds to FoldConstantArithmetic.
Given that step_vector is practically a constant, doing this early helps with DAGCombine folds that happen before type legalization. There is currently no way to test this happens earlier, although existing tests for step_vector folds continue protect the folds happening at all. Reviewed By: david-arm Differential Revision: https://reviews.llvm.org/D117863
1 parent cfe1798 commit 699e22a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5418,6 +5418,19 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
54185418
}
54195419
}
54205420

5421+
// Fold (mul step_vector(C0), C1) to (step_vector(C0 * C1)).
5422+
// (shl step_vector(C0), C1) -> (step_vector(C0 << C1))
5423+
if ((Opcode == ISD::MUL || Opcode == ISD::SHL) &&
5424+
Ops[0].getOpcode() == ISD::STEP_VECTOR) {
5425+
APInt RHSVal;
5426+
if (ISD::isConstantSplatVector(Ops[1].getNode(), RHSVal)) {
5427+
APInt NewStep = Opcode == ISD::MUL
5428+
? Ops[0].getConstantOperandAPInt(0) * RHSVal
5429+
: Ops[0].getConstantOperandAPInt(0) << RHSVal;
5430+
return getStepVector(DL, VT, NewStep);
5431+
}
5432+
}
5433+
54215434
auto IsScalarOrSameVectorSize = [NumElts](const SDValue &Op) {
54225435
return !Op.getValueType().isVector() ||
54235436
Op.getValueType().getVectorElementCount() == NumElts;

0 commit comments

Comments
 (0)