[llvm] [NVPTX] Custom lower integer<->bf16 conversions for sm_80 (PR #74827)
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 12:03:08 PST 2023
================
@@ -2580,6 +2586,37 @@ SDValue NVPTXTargetLowering::LowerFROUND64(SDValue Op,
return DAG.getNode(ISD::SELECT, SL, VT, IsLarge, A, RoundedA);
}
+SDValue NVPTXTargetLowering::LowerINT_TO_FP(SDValue Op,
+ SelectionDAG &DAG) const {
+ // sm_90 has instructions for bf16 conversions, sm_80 only has f32 -> bf16.
+ if (Op.getValueType() == MVT::bf16 &&
+ (STI.getSmVersion() < 90 || STI.getPTXVersion() < 78)) {
+ SDLoc Loc(Op);
+ return DAG.getNode(
+ ISD::FP_ROUND, Loc, MVT::bf16,
+ DAG.getNode(Op.getOpcode(), Loc, MVT::f32, Op.getOperand(0)),
+ DAG.getIntPtrConstant(0, Loc));
+ }
+
+ // Everything else is considered legal.
+ return Op;
+}
+
+SDValue NVPTXTargetLowering::LowerFP_TO_INT(SDValue Op,
+ SelectionDAG &DAG) const {
+ // sm_90 has instructions for bf16 conversions, sm_80 only has f32.
+ if (Op.getOperand(0).getValueType() == MVT::bf16 &&
+ (STI.getSmVersion() < 90 || STI.getPTXVersion() < 78)) {
+ SDLoc Loc(Op);
+ return DAG.getNode(
+ Op.getOpcode(), Loc, Op.getValueType(),
+ DAG.getNode(ISD::FP_EXTEND, Loc, MVT::f32, Op.getOperand(0)));
----------------
d0k wrote:
Looked at the SASS, both turn into a shift at SASS level. `SHF`/`USHF` instruction.
https://github.com/llvm/llvm-project/pull/74827
More information about the llvm-commits
mailing list