-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AMDGPU] Re-apply: Implement vop3p complex pattern optmization for gisel #136262
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-backend-amdgpu Author: None (Shoreshen) ChangesThis is a fix up for patch #130234, which is reverted in #136249 The main reason of building failure are:
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp:4554:1: error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type]
SmallVector<std::pair<const MachineOperand *, SrcStatus>, 4> Statlist;
SmallVector<std::pair<const MachineOperand *, SrcStatus>> Statlist;
auto [Op, Mods] = selectVOP3PModsImpl(&Root, MRI, IsDOT);
auto Results = selectVOP3PModsImpl(&Root, MRI, IsDOT);
|
@llvm/pr-subscribers-llvm-globalisel Author: None (Shoreshen) ChangesThis is a fix up for patch #130234, which is reverted in #136249 The main reason of building failure are:
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp:4554:1: error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type]
SmallVector<std::pair<const MachineOperand *, SrcStatus>, 4> Statlist;
SmallVector<std::pair<const MachineOperand *, SrcStatus>> Statlist;
auto [Op, Mods] = selectVOP3PModsImpl(&Root, MRI, IsDOT);
auto Results = selectVOP3PModsImpl(&Root, MRI, IsDOT);
|
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.
Pull Request Overview
This PR fixes build errors related to AMDGPU instruction selection and adjusts the test configuration for llvm-readobj output decoding.
- Updated the decoding from ASCII to UTF-8 in the lit test configuration.
- Modified the signature of selectVOP3PModsImpl (and related function) to correct the return type that was causing build conversion issues.
Reviewed Changes
Copilot reviewed 3 out of 7 changed files in this pull request and generated no comments.
File | Description |
---|---|
llvm/test/lit.cfg.py | Updated stdout decoding to utf-8 for reliable string interpretation. |
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h | Changed function return types to resolve type mismatch in the build. |
Files not reviewed (4)
- llvm/test/CodeGen/AMDGPU/GlobalISel/fmul.v2f16.ll: Language not supported
- llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.sdot2.ll: Language not supported
- llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.udot2.ll: Language not supported
- llvm/test/CodeGen/AMDGPU/strict_fsub.f16.ll: Language not supported
Comments suppressed due to low confidence (2)
llvm/test/lit.cfg.py:469
- Ensure that switching the decoding from 'ascii' to 'utf-8' is intentional and that the llvm-readobj output consistently uses UTF-8 encoding across all environments.
readobj_out = readobj_cmd.stdout.read().decode("utf-8")
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h:190
- The change in the return type of selectVOP3PModsImpl to use a 'const MachineOperand *' instead of 'Register' is intended to resolve conversion errors; please verify that all corresponding call sites in the implementation file have been updated accordingly.
std::pair<const MachineOperand *, unsigned>
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.
Pull Request Overview
This PR fixes build failures in the AMDGPUInstructionSelector by updating function signatures to remove structured bindings and adjust parameter/return types.
- Updated selectVOP3PModsImpl signature from taking a Register to a const MachineOperand* and modified its return type accordingly
- Replaced structured binding in selectVOP3PRetHelper with explicit variable extraction for clearer, C++20 compatible code
Files not reviewed (4)
- llvm/test/CodeGen/AMDGPU/GlobalISel/fmul.v2f16.ll: Language not supported
- llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.sdot2.ll: Language not supported
- llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.udot2.ll: Language not supported
- llvm/test/CodeGen/AMDGPU/strict_fsub.f16.ll: Language not supported
Comments suppressed due to low confidence (2)
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h:190
- Please verify that the updated parameter and return types for selectVOP3PModsImpl are consistently reflected in its implementation and all invocations.
std::pair<const MachineOperand *, unsigned> selectVOP3PModsImpl(const MachineOperand *Op, const MachineRegisterInfo &MRI, bool IsDOT = false) const;
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h:193
- Ensure that the conversion from structured bindings to explicit variable extraction in selectVOP3PRetHelper is properly implemented in the source file.
InstructionSelector::ComplexRendererFns selectVOP3PRetHelper(MachineOperand &Root, bool IsDOT = false) const;
case AMDGPU::G_CONSTANT: | ||
case AMDGPU::G_FCONSTANT: | ||
case AMDGPU::COPY: | ||
return retOpStat(&MI->getOperand(1), Curr.second, Curr); |
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.
Don't try to treat the leaf constants similar to a copy, treat them specially and directly
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.
Hi @arsenm , do you mean like this:
switch (Opc) {
case AMDGPU::G_CONSTANT:
case AMDGPU::G_FCONSTANT:
return retOpStat(&MI->getOperand(1), Curr.second, Curr);
case AMDGPU::G_BITCAST:
case AMDGPU::COPY:
return retOpStat(&MI->getOperand(1), Curr.second, Curr);
case AMDGPU::G_FNEG:
return retOpStat(&MI->getOperand(1),
getNegStatus(Curr.first, Curr.second, MRI), Curr);
default:
break;
}
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.
No, I mean you should not be attempting to inspect the operand of leaf instructions. i.e. the G_CONSTANT and G_FCONSTANT cases should not querying getOperand(1), or trying to analyze it like it's a general case.
As a helper, retOpStat shouldn't be used
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.
Pull Request Overview
This PR addresses build errors encountered in AMDGPU's VOP3P instruction selection by updating function signatures and removing structured bindings.
- Updated selectVOP3PModsImpl to return a pair containing a pointer instead of a Register.
- Introduced selectVOP3PRetHelper to eliminate structured bindings and accommodate C++20 extension issues.
Files not reviewed (4)
- llvm/test/CodeGen/AMDGPU/GlobalISel/fmul.v2f16.ll: Language not supported
- llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.sdot2.ll: Language not supported
- llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.udot2.ll: Language not supported
- llvm/test/CodeGen/AMDGPU/strict_fsub.f16.ll: Language not supported
Comments suppressed due to low confidence (2)
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h:189
- [nitpick] The updated signature of selectVOP3PModsImpl now uses a pointer instead of a Register; consider adding inline documentation to clarify this design decision and ensure consistency with its usage in the implementation.
std::pair<const MachineOperand *, unsigned> selectVOP3PModsImpl(const MachineOperand *Op, const MachineRegisterInfo &MRI,
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h:193
- [nitpick] The new selectVOP3PRetHelper function is introduced to avoid structured bindings; consider providing a comment or documentation noting its relationship to selectVOP3PModsImpl to guide future maintenance.
InstructionSelector::ComplexRendererFns selectVOP3PRetHelper(MachineOperand &Root, bool IsDOT = false) const;
e4dba98
to
6d746f3
Compare
Looks good to me but I think there are still some concerns from @arsenm that need to be resolved. |
805bab4
to
33b8294
Compare
Hi @arsenm , do you have any other requirement for this PR?? Thanks |
f8a74d4
to
a897290
Compare
return false; | ||
} | ||
|
||
// Test function, if the MI is `%reg0:n, %reg1:n = G_UNMERGE_VALUES %reg2:2n` |
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.
// Test function, if the MI is `%reg0:n, %reg1:n = G_UNMERGE_VALUES %reg2:2n` | |
/// Test function, if the MI is `%reg0:n, %reg1:n = G_UNMERGE_VALUES %reg2:2n` |
case AMDGPU::G_BITCAST: | ||
case AMDGPU::COPY: | ||
if (MI->getOperand(1).getReg().isPhysical()) | ||
return std::nullopt; | ||
return std::optional<std::pair<Register, SrcStatus>>( | ||
{MI->getOperand(1).getReg(), Curr.second}); |
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.
Separate G_BITCAST and G_COPY, the physical register input only applies to COPY
return std::optional<std::pair<Register, SrcStatus>>( | ||
{MI->getOperand(1).getReg(), Stat}); |
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.
return std::optional<std::pair<Register, SrcStatus>>( | |
{MI->getOperand(1).getReg(), Stat}); | |
return {MI->getOperand(1).getReg(), Stat}); |
Don't need to repeat all of these types throughout
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.
Hi @arsenm , this is returning an optional value so doing that will cause compilation failure.....
return std::nullopt; | ||
} | ||
|
||
class searchOptions { |
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.
Capitalize
class searchOptions { | ||
private: | ||
bool HasNeg = false; | ||
// Assume all complex pattern of VOP3P has opsel. |
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.
// Assume all complex pattern of VOP3P has opsel. | |
// Assume all complex pattern of VOP3P have opsel. |
BuildMI(*BB, MI, MI->getDebugLoc(), TII.get(AMDGPU::COPY), DstReg) | ||
.addReg(NewReg); | ||
|
||
// only accept VGPR. |
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.
Capitalize
|
||
static std::pair<Register, SrcStatus> | ||
getLastSameOrNeg(Register Reg, const MachineRegisterInfo &MRI, | ||
searchOptions SearchOptions, int MaxDepth = 6) { |
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 still think this whole thing is overcomplicating the problem. You shouldn't need to do an arbitrary depth analysis. At most it's probably 3. Anything deeper is running into missed combine opportunities
|
||
while (Depth <= MaxDepth && Curr.has_value()) { | ||
Depth++; | ||
if (SearchOptions.checkOptions(Curr.value().second)) { |
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.
Avoid repeating the .value().second so many times
HasNeg = true; | ||
} | ||
} | ||
bool checkOptions(SrcStatus Stat) const { |
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.
Don't understand this
return std::nullopt; | ||
} | ||
|
||
class searchOptions { |
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.
Document and the name could be better. Why does the search need options? What kind of search?
This is a fix up for patch #130234, which is reverted in #136249
The main reason of building failure are:
Both error cannot be reproduced at my local machine, the fix applied are:
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
functiongetSrcStats
replacellvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
functionAMDGPUInstructionSelector::selectVOP3PRetHelper
replaceThese change hasn't be testified since both errors cannot be reproduced in local