[PATCH] D117863: [ISEL] Move trivial step_vector folds to FoldConstantArithmetic.
Sander de Smalen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 21 01:09:38 PST 2022
sdesmalen created this revision.
Herald added subscribers: ecnelises, steven.zhang, hiraditya.
sdesmalen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117863
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5413,6 +5413,19 @@
}
}
+ // Fold (mul step_vector(C0), C1) to (step_vector(C0 * C1)).
+ // (shl step_vector(C0), C1) -> (step_vector(C0 << C1))
+ if ((Opcode == ISD::MUL || Opcode == ISD::SHL) &&
+ Ops[0].getOpcode() == ISD::STEP_VECTOR) {
+ APInt RHSVal;
+ if (ISD::isConstantSplatVector(Ops[1].getNode(), RHSVal)) {
+ APInt NewStep = Opcode == ISD::MUL
+ ? Ops[0].getConstantOperandAPInt(0) * RHSVal
+ : Ops[0].getConstantOperandAPInt(0) << RHSVal;
+ return getStepVector(DL, VT, NewStep);
+ }
+ }
+
auto IsScalarOrSameVectorSize = [NumElts](const SDValue &Op) {
return !Op.getValueType().isVector() ||
Op.getValueType().getVectorElementCount() == NumElts;
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -3946,15 +3946,6 @@
return DAG.getVScale(SDLoc(N), VT, C0 * C1);
}
- // Fold (mul step_vector(C0), C1) to (step_vector(C0 * C1)).
- APInt MulVal;
- if (N0.getOpcode() == ISD::STEP_VECTOR)
- if (ISD::isConstantSplatVector(N1.getNode(), MulVal)) {
- const APInt &C0 = N0.getConstantOperandAPInt(0);
- APInt NewStep = C0 * MulVal;
- return DAG.getStepVector(SDLoc(N), VT, NewStep);
- }
-
// Fold ((mul x, 0/undef) -> 0,
// (mul x, 1) -> x) -> x)
// -> and(x, mask)
@@ -8666,17 +8657,6 @@
return DAG.getVScale(SDLoc(N), VT, C0 << C1);
}
- // Fold (shl step_vector(C0), C1) to (step_vector(C0 << C1)).
- APInt ShlVal;
- if (N0.getOpcode() == ISD::STEP_VECTOR)
- if (ISD::isConstantSplatVector(N1.getNode(), ShlVal)) {
- const APInt &C0 = N0.getConstantOperandAPInt(0);
- if (ShlVal.ult(C0.getBitWidth())) {
- APInt NewStep = C0 << ShlVal;
- return DAG.getStepVector(SDLoc(N), VT, NewStep);
- }
- }
-
return SDValue();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117863.401893.patch
Type: text/x-patch
Size: 2250 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220121/3f10f132/attachment.bin>
More information about the llvm-commits
mailing list