-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[llvm][AMDGPU] Implemented isProfitableToHoist and isFMAFasterThanFMulAndFAdd #108756
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 all commits
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 |
|---|---|---|
|
|
@@ -891,6 +891,37 @@ bool AMDGPUTargetLowering::isCheapToSpeculateCtlz(Type *Ty) const { | |
| return true; | ||
| } | ||
|
|
||
| bool AMDGPUTargetLowering::isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, | ||
| EVT VT) const { | ||
| VT = VT.getScalarType(); | ||
|
|
||
| if (!VT.isSimple()) | ||
| return false; | ||
|
|
||
| switch (VT.getSimpleVT().SimpleTy) { | ||
| case MVT::f16: | ||
| return Subtarget->hasFullFP16(); | ||
| case MVT::f32: | ||
| case MVT::f64: | ||
| return true; | ||
| default: | ||
| break; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| bool AMDGPUTargetLowering::isFMAFasterThanFMulAndFAdd(const Function &F, | ||
| Type *Ty) const { | ||
| switch (Ty->getScalarType()->getTypeID()) { | ||
| case Type::FloatTyID: | ||
| case Type::DoubleTyID: | ||
| return true; | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| bool AMDGPUTargetLowering::isSDNodeAlwaysUniform(const SDNode *N) const { | ||
| switch (N->getOpcode()) { | ||
| case ISD::EntryToken: | ||
|
|
@@ -1000,6 +1031,33 @@ bool AMDGPUTargetLowering::isTruncateFree(Type *Source, Type *Dest) const { | |
| return DestSize < SrcSize && DestSize % 32 == 0; | ||
| } | ||
|
|
||
| /// Check if it is profitable to hoist instruction in then/else to if. | ||
| /// Not profitable if I and it's user can form a FMA instruction | ||
| /// because we prefer FMSUB/FMADD. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments copied from AArch64 |
||
| bool AMDGPUTargetLowering::isProfitableToHoist(Instruction *I) const { | ||
| if (I->getOpcode() != Instruction::FMul) | ||
| return true; | ||
|
|
||
| if (!I->hasOneUse()) | ||
| return true; | ||
|
|
||
| Instruction *User = I->user_back(); | ||
|
|
||
| if (!(User->getOpcode() == Instruction::FSub || | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Push negate through parentheses |
||
| User->getOpcode() == Instruction::FAdd)) | ||
| return true; | ||
|
|
||
| const TargetOptions &Options = getTargetMachine().Options; | ||
| const Function *F = I->getFunction(); | ||
| const DataLayout &DL = F->getDataLayout(); | ||
| Type *Ty = User->getOperand(0)->getType(); | ||
|
|
||
| return !( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, demorgan this. Should also check legality first |
||
| isFMAFasterThanFMulAndFAdd(*F, Ty) && | ||
| isOperationLegalOrCustom(ISD::FMA, getValueType(DL, Ty)) && | ||
| (Options.AllowFPOpFusion == FPOpFusion::Fast || Options.UnsafeFPMath)); | ||
| } | ||
|
|
||
| bool AMDGPUTargetLowering::isZExtFree(Type *Src, Type *Dest) const { | ||
| unsigned SrcSize = Src->getScalarSizeInBits(); | ||
| unsigned DestSize = Dest->getScalarSizeInBits(); | ||
|
|
||
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 should have the same logic as the EVT variant, this is the aarch64 logic
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.
Also will probably be easier to move this down to SITargetLowering