[llvm] Porting `LowerFP_TO_INT()` and LowerINT_TO_FP()` to `TargetLowering.cpp` (PR #118831)
Aidan Goldfarb via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 5 09:29:31 PST 2024
https://github.com/AidanGoldfarb updated https://github.com/llvm/llvm-project/pull/118831
>From a1d09724c318aa24c8bd26b90a6dd62fb4125784 Mon Sep 17 00:00:00 2001
From: Aidan <aidan.goldfarb at mail.mcgill.ca>
Date: Thu, 5 Dec 2024 12:10:50 -0500
Subject: [PATCH 1/2] draft commit for targetlowering port
---
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index eeba4b7d20f9c1..0f21eae7883dea 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -8413,6 +8413,17 @@ bool TargetLowering::expandUINT_TO_FP(SDNode *Node, SDValue &Result,
EVT SrcVT = Src.getValueType();
EVT DstVT = Node->getValueType(0);
+ if (DstVT == MVT::bf16) {
+ SDLoc Loc(Node);
+ SDValue Operand = Node->getOperand(0);
+
+ Result = DAG.getNode(
+ ISD::FP_ROUND, Loc, MVT::bf16,
+ DAG.getNode(ISD::UINT_TO_FP, Loc, MVT::f32, Operand),
+ DAG.getIntPtrConstant(0, Loc));
+ return true;
+ }
+
// If the input is known to be non-negative and SINT_TO_FP is legal then use
// it.
if (Node->getFlags().hasNonNeg() &&
>From f265bb42c4cdc01e8f7595118d8c2630df668205 Mon Sep 17 00:00:00 2001
From: Aidan <aidan.goldfarb at mail.mcgill.ca>
Date: Thu, 5 Dec 2024 12:29:19 -0500
Subject: [PATCH 2/2] formatting fix
---
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 0f21eae7883dea..76c8c14e9be100 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -8417,8 +8417,7 @@ bool TargetLowering::expandUINT_TO_FP(SDNode *Node, SDValue &Result,
SDLoc Loc(Node);
SDValue Operand = Node->getOperand(0);
- Result = DAG.getNode(
- ISD::FP_ROUND, Loc, MVT::bf16,
+ Result = DAG.getNode(ISD::FP_ROUND, Loc, MVT::bf16,
DAG.getNode(ISD::UINT_TO_FP, Loc, MVT::f32, Operand),
DAG.getIntPtrConstant(0, Loc));
return true;
More information about the llvm-commits
mailing list