[llvm] [LLVM][NVPTX]Add BF16 vector instruction and fix lowering rules (PR #69415)
Han Shen via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 19 23:49:10 PDT 2023
================
@@ -769,14 +783,27 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
// promoted to f32. v2f16 is expanded to f16, which is then promoted
// to f32.
for (const auto &Op :
- {ISD::FDIV, ISD::FREM, ISD::FSQRT, ISD::FSIN, ISD::FCOS, ISD::FABS}) {
+ {ISD::FDIV, ISD::FREM, ISD::FSQRT, ISD::FSIN, ISD::FCOS}) {
setOperationAction(Op, MVT::f16, Promote);
setOperationAction(Op, MVT::bf16, Promote);
setOperationAction(Op, MVT::f32, Legal);
setOperationAction(Op, MVT::f64, Legal);
setOperationAction(Op, MVT::v2f16, Expand);
setOperationAction(Op, MVT::v2bf16, Expand);
+ if (getOperationAction(Op, MVT::bf16) == Promote)
+ AddPromotedToType(Op, MVT::bf16, MVT::f32);
+ }
+ for (const auto &Op : {ISD::FABS}) {
+ setOperationAction(Op, MVT::f16, Promote);
+ setBF16OperationAction(Op, MVT::bf16, Legal, Promote);
+ setOperationAction(Op, MVT::f32, Legal);
+ setOperationAction(Op, MVT::f64, Legal);
+ setOperationAction(Op, MVT::v2f16, Expand);
+ setBF16OperationAction(Op, MVT::v2bf16, Legal, Expand);
+ if (getOperationAction(Op, MVT::bf16) == Promote)
----------------
shenh10 wrote:
Another implementation possibility is to add a special case in [getTypeToPromoteTo()](https://github.com/llvm/llvm-project/blob/f2517cbceec0bd9b049ba24f36cb3a2508c988fa/llvm/include/llvm/CodeGen/TargetLowering.h#L1567) to promote bf16 to f32, the advantage is to declare it for all Ops, while might not be that gentle as well.
https://github.com/llvm/llvm-project/pull/69415
More information about the llvm-commits
mailing list