-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Move the rest of Zfa FLI instruction handling to lowerConstantFP. #109217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…tFP. We already moved the fneg case. This moves the rest so we can drop the custom isel.
@llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesWe already moved the fneg case. This moves the rest so we can drop the custom isel. Full diff: https://github.com/llvm/llvm-project/pull/109217.diff 2 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index f22ab1e5e9d48a..fcd46b5921c4de 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -889,29 +889,6 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
}
case ISD::ConstantFP: {
const APFloat &APF = cast<ConstantFPSDNode>(Node)->getValueAPF();
- int FPImm = static_cast<const RISCVTargetLowering *>(TLI)->getLegalZfaFPImm(
- APF, VT);
- if (FPImm >= 0) {
- unsigned Opc;
- switch (VT.SimpleTy) {
- default:
- llvm_unreachable("Unexpected size");
- case MVT::f16:
- Opc = RISCV::FLI_H;
- break;
- case MVT::f32:
- Opc = RISCV::FLI_S;
- break;
- case MVT::f64:
- Opc = RISCV::FLI_D;
- break;
- }
- SDNode *Res = CurDAG->getMachineNode(
- Opc, DL, VT, CurDAG->getTargetConstant(FPImm, DL, XLenVT));
-
- ReplaceNode(Node, Res);
- return;
- }
bool NegZeroF64 = APF.isNegZero() && VT == MVT::f64;
SDValue Imm;
@@ -3552,13 +3529,6 @@ bool RISCVDAGToDAGISel::selectScalarFPAsInt(SDValue N, SDValue &Imm) {
MVT VT = CFP->getSimpleValueType(0);
- // Even if this FPImm requires an additional FNEG (i.e. the second element of
- // the returned pair is true) we still prefer FLI + FNEG over immediate
- // materialization as the latter might generate a longer instruction sequence.
- if (static_cast<const RISCVTargetLowering *>(TLI)->getLegalZfaFPImm(APF,
- VT) >= 0)
- return false;
-
MVT XLenVT = Subtarget->getXLenVT();
if (VT == MVT::f64 && !Subtarget->is64Bit()) {
assert(APF.isNegZero() && "Unexpected constant.");
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 189fb741f34cd1..fc12c88445200d 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -2268,9 +2268,6 @@ bool RISCVTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
if (!IsLegalVT)
return false;
- if (getLegalZfaFPImm(Imm, VT) >= 0)
- return true;
-
// Cannot create a 64 bit floating-point immediate value for rv32.
if (Subtarget.getXLen() < VT.getScalarSizeInBits()) {
// td can handle +0.0 or -0.0 already.
@@ -5802,22 +5799,29 @@ SDValue RISCVTargetLowering::lowerConstantFP(SDValue Op,
MVT VT = Op.getSimpleValueType();
const APFloat &Imm = cast<ConstantFPSDNode>(Op)->getValueAPF();
- if (getLegalZfaFPImm(Imm, VT) >= 0)
- return Op;
+ // Can this constant be select by a Zfa FLI instruction?
+ bool Negate = false;
+ int Index = getLegalZfaFPImm(Imm, VT);
- if (!Imm.isNegative())
- return SDValue();
+ // If the constant is negative, try negating.
+ if (Index < 0 && Imm.isNegative()) {
+ Index = getLegalZfaFPImm(-Imm, VT);
+ Negate = true;
+ }
- int Index = getLegalZfaFPImm(-Imm, VT);
+ // If we couldn't find a FLI lowering, fall back to generic code.
if (Index < 0)
return SDValue();
// Emit an FLI+FNEG. We use a custom node to hide from constant folding.
SDLoc DL(Op);
SDValue Const =
- DAG.getNode(RISCVISD::FLI, Op, VT,
+ DAG.getNode(RISCVISD::FLI, DL, VT,
DAG.getTargetConstant(Index, DL, Subtarget.getXLenVT()));
- return DAG.getNode(ISD::FNEG, Op, VT, Const);
+ if (!Negate)
+ return Const;
+
+ return DAG.getNode(ISD::FNEG, DL, VT, Const);
}
static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG,
|
This patch is not NFC.
Before:
After:
|
Thanks. I'll take look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@@ -5802,22 +5802,29 @@ SDValue RISCVTargetLowering::lowerConstantFP(SDValue Op, | |||
MVT VT = Op.getSimpleValueType(); | |||
const APFloat &Imm = cast<ConstantFPSDNode>(Op)->getValueAPF(); | |||
|
|||
if (getLegalZfaFPImm(Imm, VT) >= 0) | |||
return Op; | |||
// Can this constant be select by a Zfa FLI instruction? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit: "select" -> "selected"
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/134/builds/5612 Here is the relevant piece of the build log for the reference
|
We already moved the fneg case. This moves the rest so we can drop the custom isel.