Skip to content

AMDGPU: Use OtherPredicates for v_dot2_bf16_bf16(f16_f16) pseudo #84354

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

Merged
merged 1 commit into from
Mar 7, 2024
Merged

AMDGPU: Use OtherPredicates for v_dot2_bf16_bf16(f16_f16) pseudo #84354

merged 1 commit into from
Mar 7, 2024

Conversation

changpeng
Copy link
Contributor

This is because SubtargetPredicate is not copied from pseudo to dpp16 and dpp8 real. Actually this is the common issue for insts with Realtriple --- We should avoid using SubtargetPredicate to define pseudo: the predicate will be lost in real.

  This is because SubtargetPredicate is not copied from pseudo to
dpp16 and dpp8 real. Actually this is the common issue for insts
with _Realtriple_ --- We should avoid using SubtargetPredicate
to define pseudo: the predicate will be lost in real.
@llvmbot
Copy link
Member

llvmbot commented Mar 7, 2024

@llvm/pr-subscribers-backend-amdgpu

Author: Changpeng Fang (changpeng)

Changes

This is because SubtargetPredicate is not copied from pseudo to dpp16 and dpp8 real. Actually this is the common issue for insts with Realtriple --- We should avoid using SubtargetPredicate to define pseudo: the predicate will be lost in real.


Full diff: https://github.com/llvm/llvm-project/pull/84354.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/VOP3Instructions.td (+1-1)
diff --git a/llvm/lib/Target/AMDGPU/VOP3Instructions.td b/llvm/lib/Target/AMDGPU/VOP3Instructions.td
index 334cfad478f151..3340ded9d36000 100644
--- a/llvm/lib/Target/AMDGPU/VOP3Instructions.td
+++ b/llvm/lib/Target/AMDGPU/VOP3Instructions.td
@@ -893,7 +893,7 @@ let SubtargetPredicate = isGFX12Plus, ReadsModeReg = 0 in {
   defm V_MINIMUMMAXIMUM_F16 : VOP3Inst<"v_minimummaximum_f16", VOP3_Profile<VOP_F16_F16_F16_F16, VOP3_OPSEL>>;
 } // End SubtargetPredicate = isGFX12Plus, ReadsModeReg = 0
 
-let SubtargetPredicate = HasDot9Insts, IsDOT=1 in {
+let OtherPredicates = [HasDot9Insts], IsDOT=1 in {
   defm V_DOT2_F16_F16 :   VOP3Inst<"v_dot2_f16_f16",   VOP3_DOT_Profile<VOP_F16_V2F16_V2F16_F16>, int_amdgcn_fdot2_f16_f16>;
   defm V_DOT2_BF16_BF16 : VOP3Inst<"v_dot2_bf16_bf16", VOP3_DOT_Profile<VOP_BF16_V2BF16_V2BF16_BF16>, int_amdgcn_fdot2_bf16_bf16>;
 }

@changpeng changpeng requested a review from jayfoad March 7, 2024 18:13
Copy link
Collaborator

@rampitec rampitec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but this is really unfortunate. Can we try to address dpp predicates?

@changpeng
Copy link
Contributor Author

LGTM, but this is really unfortunate. Can we try to address dpp predicates?

let SubtargetPredicate = HasDPP8;

I am thinking whether we can put hasDPP8 into OtherPredicates (using concat). But we need to be
very careful of the ordering this assignment with copy from pseudo to real of OtherPredicates.

@changpeng
Copy link
Contributor Author

LGTM, but this is really unfortunate. Can we try to address dpp predicates?

let SubtargetPredicate = HasDPP8;

I am thinking whether we can put hasDPP8 into OtherPredicates (using concat). But we need to be very careful of the ordering this assignment with copy from pseudo to real of OtherPredicates.

let SubtargetPredicate = HasDPP8; // do we really need?
let AssemblerPredicate = HasDPP8;

Actually why do we need to set both SubtargetPredicate and AssemblerPredicate? One of them enough?
"AssemblerPredicate = HasDPP8" may also have "overriden" issue on the path.

@changpeng changpeng merged commit 9286665 into llvm:main Mar 7, 2024
@rampitec
Copy link
Collaborator

rampitec commented Mar 7, 2024

LGTM, but this is really unfortunate. Can we try to address dpp predicates?

let SubtargetPredicate = HasDPP8;
I am thinking whether we can put hasDPP8 into OtherPredicates (using concat). But we need to be very careful of the ordering this assignment with copy from pseudo to real of OtherPredicates.

let SubtargetPredicate = HasDPP8; // do we really need? let AssemblerPredicate = HasDPP8;

Actually why do we need to set both SubtargetPredicate and AssemblerPredicate? One of them enough? "AssemblerPredicate = HasDPP8" may also have "overriden" issue on the path.

Imagine you have the same instruction in different targets, so you are using 'SubtargetPredicate = HasFeature' on the pseudo. But the encoding is different, so you this HasFeature is not sufficient, you need to use AssemblerPredicate to distinguish between targets for real instructions.

@changpeng
Copy link
Contributor Author

changpeng commented Mar 7, 2024

LGTM, but this is really unfortunate. Can we try to address dpp predicates?

let SubtargetPredicate = HasDPP8;
I am thinking whether we can put hasDPP8 into OtherPredicates (using concat). But we need to be very careful of the ordering this assignment with copy from pseudo to real of OtherPredicates.

let SubtargetPredicate = HasDPP8; // do we really need? let AssemblerPredicate = HasDPP8;
Actually why do we need to set both SubtargetPredicate and AssemblerPredicate? One of them enough? "AssemblerPredicate = HasDPP8" may also have "overriden" issue on the path.

Imagine you have the same instruction in different targets, so you are using 'SubtargetPredicate = HasFeature' on the pseudo. But the encoding is different, so you this HasFeature is not sufficient, you need to use AssemblerPredicate to distinguish between targets for real instructions.

Is it redundant to have HasDPP8 in both SubtargetPredicate and AssemblerPredicate for a real?
I think it is SubtargetPredicate && AssemblerPredicate

@rampitec
Copy link
Collaborator

rampitec commented Mar 7, 2024

LGTM, but this is really unfortunate. Can we try to address dpp predicates?

let SubtargetPredicate = HasDPP8;
I am thinking whether we can put hasDPP8 into OtherPredicates (using concat). But we need to be very careful of the ordering this assignment with copy from pseudo to real of OtherPredicates.

let SubtargetPredicate = HasDPP8; // do we really need? let AssemblerPredicate = HasDPP8;
Actually why do we need to set both SubtargetPredicate and AssemblerPredicate? One of them enough? "AssemblerPredicate = HasDPP8" may also have "overriden" issue on the path.

Imagine you have the same instruction in different targets, so you are using 'SubtargetPredicate = HasFeature' on the pseudo. But the encoding is different, so you this HasFeature is not sufficient, you need to use AssemblerPredicate to distinguish between targets for real instructions.

Is it redundant to have HasDPP8 in both SubtargetPredicate and AssemblerPredicate for a real? I think it is SubtargetPredicate && AssemblerPredicate

Yes, both should not be needed.

@changpeng
Copy link
Contributor Author

LGTM, but this is really unfortunate. Can we try to address dpp predicates?

let SubtargetPredicate = HasDPP8;
I am thinking whether we can put hasDPP8 into OtherPredicates (using concat). But we need to be very careful of the ordering this assignment with copy from pseudo to real of OtherPredicates.

let SubtargetPredicate = HasDPP8; // do we really need? let AssemblerPredicate = HasDPP8;
Actually why do we need to set both SubtargetPredicate and AssemblerPredicate? One of them enough? "AssemblerPredicate = HasDPP8" may also have "overriden" issue on the path.

Imagine you have the same instruction in different targets, so you are using 'SubtargetPredicate = HasFeature' on the pseudo. But the encoding is different, so you this HasFeature is not sufficient, you need to use AssemblerPredicate to distinguish between targets for real instructions.

Is it redundant to have HasDPP8 in both SubtargetPredicate and AssemblerPredicate for a real? I think it is SubtargetPredicate && AssemblerPredicate

Yes, both should not be needed.

Then we can remove "let SubtargetPredicate = ...", and copy SubtargetPredicate from pseudo to real for dpp16 and dpp8.
I am going to look into this. Thanks

@changpeng
Copy link
Contributor Author

LGTM, but this is really unfortunate. Can we try to address dpp predicates?

let SubtargetPredicate = HasDPP8;
I am thinking whether we can put hasDPP8 into OtherPredicates (using concat). But we need to be very careful of the ordering this assignment with copy from pseudo to real of OtherPredicates.

let SubtargetPredicate = HasDPP8; // do we really need? let AssemblerPredicate = HasDPP8;
Actually why do we need to set both SubtargetPredicate and AssemblerPredicate? One of them enough? "AssemblerPredicate = HasDPP8" may also have "overriden" issue on the path.

Imagine you have the same instruction in different targets, so you are using 'SubtargetPredicate = HasFeature' on the pseudo. But the encoding is different, so you this HasFeature is not sufficient, you need to use AssemblerPredicate to distinguish between targets for real instructions.

Is it redundant to have HasDPP8 in both SubtargetPredicate and AssemblerPredicate for a real? I think it is SubtargetPredicate && AssemblerPredicate

Yes, both should not be needed.

Then we can remove "let SubtargetPredicate = ...", and copy SubtargetPredicate from pseudo to real for dpp16 and dpp8. I am going to look into this. Thanks

#84517

changpeng added a commit that referenced this pull request Mar 8, 2024
#84517)

We usually expect to copy SubtargetPredicate (and OtherPredicates) from
pseudo to real. However, in dpp16 and dpp8, there are assignments like
SubtargetPredicate = HasDPP/HasDPP16/HasDpp8. These assignments override
predicates copied from pseudo, and thus the predicates used to define
pseudo get lost.

Losing predicates is a subtle issue usually not easy to be found. It may
result in instructions being generated on GPUs that do not support the
features to generate them.
#84354 addressed one of such
issues, and inspired this work.

Fortunately, we found that the assignment of SubtargetPredicate usually
comes together with assignment of AssemblerPredicate, and with the same
value. For example:
  let AssemblerPredicate = HasDPP16;
  let SubtargetPredicate = HasDPP16;
One of them is redundant and can be removed.

In this work, we remove the redundant assignment of SubtargetPredicate,
and then copy it from pseudo for VOP*_DPP and VOP*_DPP8. With this
change, we can safely use SubtargetPredicate to define pseudo
instructions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants