[llvm] [LLVM][NVPTX]Add BF16 vector instruction and fix lowering rules (PR #69415)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 10:04:29 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)
----------------
Artem-B wrote:
> the enum declaration of floating type is bf16 -> f16->f32->f64->f80, thus bf16 would fallback to f16 in this rule, which is not what we expects.
Yeah. Both bf16 and f16 should be promoted to f32. We should fix that in a separate patch.
Explicitly specifying promotion type is OK, but this looks like a generic issue that should be fixed for everyone.
https://github.com/llvm/llvm-project/pull/69415
More information about the llvm-commits
mailing list