-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[RISCV][CostModel] Add cost for fabs/fsqrt of type bf16/f16 #118608
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
Changes from 3 commits
48dfe67
e682e00
86bd2f7
0b5f44e
1fe4655
b7c046f
3bb8859
1a8c67e
5d2432f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1035,21 +1035,44 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, | |
| } | ||
| break; | ||
| } | ||
| case Intrinsic::fabs: | ||
| case Intrinsic::fabs: { | ||
| auto LT = getTypeLegalizationCost(RetTy); | ||
| if (ST->hasVInstructions() && LT.second.isVector()) { | ||
| // lui a0, 8 | ||
| // addi a0, a0, -1 | ||
| // vsetvli a1, zero, e16, m1, ta, ma | ||
| // vand.vx v8, v8, a0 | ||
| // f16 with zvfhmin and bf16 with zvfhbmin | ||
| if (LT.second.getVectorElementType() == MVT::bf16 || | ||
| (LT.second.getVectorElementType() == MVT::f16 && | ||
| !ST->hasVInstructionsF16())) | ||
| return LT.first * getRISCVInstructionCost(RISCV::VAND_VX, LT.second, | ||
| CostKind) + | ||
| 2; | ||
| else | ||
| return LT.first * | ||
| getRISCVInstructionCost(RISCV::VFSGNJX_VV, LT.second, CostKind); | ||
| } | ||
| break; | ||
| } | ||
| case Intrinsic::sqrt: { | ||
| auto LT = getTypeLegalizationCost(RetTy); | ||
| // TODO: add f16/bf16, bf16 with zvfbfmin && f16 with zvfhmin | ||
| auto NVT = LT.second; | ||
| if (ST->hasVInstructions() && LT.second.isVector()) { | ||
| unsigned Op; | ||
| switch (ICA.getID()) { | ||
| case Intrinsic::fabs: | ||
| Op = RISCV::VFSGNJX_VV; | ||
| break; | ||
| case Intrinsic::sqrt: | ||
| Op = RISCV::VFSQRT_V; | ||
| break; | ||
| SmallVector<unsigned, 3> Opcodes; | ||
| // f16 with zvfhmin and bf16 with zvfbfmin | ||
| if (LT.second.getVectorElementType() == MVT::bf16) { | ||
| Opcodes = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFSQRT_V, | ||
| RISCV::VFNCVTBF16_F_F_W}; | ||
| NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT); | ||
| } else if (LT.second.getVectorElementType() == MVT::f16 && | ||
| !ST->hasVInstructionsF16()) { | ||
| Opcodes = {RISCV::VFWCVT_F_F_V, RISCV::VFSQRT_V, RISCV::VFNCVT_F_F_W}; | ||
| NVT = TLI->getTypeToPromoteTo(ISD::FSQRT, NVT); | ||
|
||
| } else { | ||
| Opcodes = {RISCV::VFSQRT_V}; | ||
| } | ||
| return LT.first * getRISCVInstructionCost(Op, LT.second, CostKind); | ||
| return LT.first * getRISCVInstructionCost(Opcodes, NVT, CostKind); | ||
| } | ||
| break; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
I don't think this works for <vscale x 32 x bfloat>. We use
setOperationAction(ISD::FSQRT, MVT::v32bf16, Custom)instead ofPromote.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.
This is indeed a problem. Is the cost of <vscale x 32 x bfloat> double the cost of <vscale x 16x bfloat>?