aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2023-05-12 12:34:07 -0700
committerCraig Topper <craig.topper@sifive.com>2023-05-12 12:34:23 -0700
commit39fe48b74eeaa037874f1117f76c4916dc722743 (patch)
tree0bb5b3b0ec7a98ee3ab43f368effc337c42c06b4 /llvm/lib
parentbe71d4cc5010cf6e52aafc430691afd12a1c07c6 (diff)
downloadllvm-39fe48b74eeaa037874f1117f76c4916dc722743.zip
llvm-39fe48b74eeaa037874f1117f76c4916dc722743.tar.gz
llvm-39fe48b74eeaa037874f1117f76c4916dc722743.tar.bz2
[RISCV] Move VFMADD_VL DAG combine to a function. NFC
This is preparation for an additional combine.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/RISCV/RISCVISelLowering.cpp75
1 files changed, 39 insertions, 36 deletions
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 65647b6..d4df9b1 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -11201,6 +11201,43 @@ static unsigned negateFMAOpcode(unsigned Opcode, bool NegMul, bool NegAcc) {
return Opcode;
}
+static SDValue performVFMADD_VLCombine(SDNode *N, SelectionDAG &DAG) {
+ // Fold FNEG_VL into FMA opcodes.
+ // The first operand of strict-fp is chain.
+ unsigned Offset = N->isTargetStrictFPOpcode();
+ SDValue A = N->getOperand(0 + Offset);
+ SDValue B = N->getOperand(1 + Offset);
+ SDValue C = N->getOperand(2 + Offset);
+ SDValue Mask = N->getOperand(3 + Offset);
+ SDValue VL = N->getOperand(4 + Offset);
+
+ auto invertIfNegative = [&Mask, &VL](SDValue &V) {
+ if (V.getOpcode() == RISCVISD::FNEG_VL && V.getOperand(1) == Mask &&
+ V.getOperand(2) == VL) {
+ // Return the negated input.
+ V = V.getOperand(0);
+ return true;
+ }
+
+ return false;
+ };
+
+ bool NegA = invertIfNegative(A);
+ bool NegB = invertIfNegative(B);
+ bool NegC = invertIfNegative(C);
+
+ // If no operands are negated, we're done.
+ if (!NegA && !NegB && !NegC)
+ return SDValue();
+
+ unsigned NewOpcode = negateFMAOpcode(N->getOpcode(), NegA != NegB, NegC);
+ if (N->isTargetStrictFPOpcode())
+ return DAG.getNode(NewOpcode, SDLoc(N), N->getVTList(),
+ {N->getOperand(0), A, B, C, Mask, VL});
+ return DAG.getNode(NewOpcode, SDLoc(N), N->getValueType(0), A, B, C, Mask,
+ VL);
+}
+
static SDValue performSRACombine(SDNode *N, SelectionDAG &DAG,
const RISCVSubtarget &Subtarget) {
assert(N->getOpcode() == ISD::SRA && "Unexpected opcode");
@@ -12073,42 +12110,8 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
case RISCVISD::STRICT_VFMADD_VL:
case RISCVISD::STRICT_VFNMADD_VL:
case RISCVISD::STRICT_VFMSUB_VL:
- case RISCVISD::STRICT_VFNMSUB_VL: {
- // Fold FNEG_VL into FMA opcodes.
- // The first operand of strict-fp is chain.
- unsigned Offset = N->isTargetStrictFPOpcode();
- SDValue A = N->getOperand(0 + Offset);
- SDValue B = N->getOperand(1 + Offset);
- SDValue C = N->getOperand(2 + Offset);
- SDValue Mask = N->getOperand(3 + Offset);
- SDValue VL = N->getOperand(4 + Offset);
-
- auto invertIfNegative = [&Mask, &VL](SDValue &V) {
- if (V.getOpcode() == RISCVISD::FNEG_VL && V.getOperand(1) == Mask &&
- V.getOperand(2) == VL) {
- // Return the negated input.
- V = V.getOperand(0);
- return true;
- }
-
- return false;
- };
-
- bool NegA = invertIfNegative(A);
- bool NegB = invertIfNegative(B);
- bool NegC = invertIfNegative(C);
-
- // If no operands are negated, we're done.
- if (!NegA && !NegB && !NegC)
- return SDValue();
-
- unsigned NewOpcode = negateFMAOpcode(N->getOpcode(), NegA != NegB, NegC);
- if (Offset > 0)
- return DAG.getNode(NewOpcode, SDLoc(N), N->getVTList(),
- {N->getOperand(0), A, B, C, Mask, VL});
- return DAG.getNode(NewOpcode, SDLoc(N), N->getValueType(0), A, B, C, Mask,
- VL);
- }
+ case RISCVISD::STRICT_VFNMSUB_VL:
+ return performVFMADD_VLCombine(N, DAG);
case ISD::LOAD:
case ISD::STORE: {
if (DCI.isAfterLegalizeDAG())