-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[AMDGPU][GlobalISel] Combine (sext (trunc (sext_in_reg x))) #131312
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
Closed
Pierre-vh
wants to merge
1
commit into
users/pierre-vh/sifold-bitmasks
from
users/pierre-vh/combine-sext-trunc-sextinreg
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
llvm/test/CodeGen/AMDGPU/GlobalISel/combine-sext-trunc-sextinreg.mir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py | ||
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1030 -run-pass=amdgpu-postlegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s | ||
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1030 -run-pass=amdgpu-regbank-combiner -verify-machineinstrs %s -o - | FileCheck %s | ||
|
||
--- | ||
name: trunc_s16_inreg_8 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0: | ||
liveins: $vgpr0 | ||
; CHECK-LABEL: name: trunc_s16_inreg_8 | ||
; CHECK: liveins: $vgpr0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: %copy:_(s32) = COPY $vgpr0 | ||
; CHECK-NEXT: %inreg:_(s32) = G_SEXT_INREG %copy, 8 | ||
; CHECK-NEXT: $vgpr0 = COPY %inreg(s32) | ||
%copy:_(s32) = COPY $vgpr0 | ||
%inreg:_(s32) = G_SEXT_INREG %copy, 8 | ||
%trunc:_(s16) = G_TRUNC %inreg | ||
%sext:_(s32) = G_SEXT %trunc | ||
$vgpr0 = COPY %sext | ||
... | ||
|
||
--- | ||
name: trunc_s16_inreg_16 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0: | ||
liveins: $vgpr0 | ||
; CHECK-LABEL: name: trunc_s16_inreg_16 | ||
; CHECK: liveins: $vgpr0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: %copy:_(s32) = COPY $vgpr0 | ||
; CHECK-NEXT: %inreg:_(s32) = G_SEXT_INREG %copy, 16 | ||
; CHECK-NEXT: $vgpr0 = COPY %inreg(s32) | ||
%copy:_(s32) = COPY $vgpr0 | ||
%inreg:_(s32) = G_SEXT_INREG %copy, 16 | ||
%trunc:_(s16) = G_TRUNC %inreg | ||
%sext:_(s32) = G_SEXT %trunc | ||
$vgpr0 = COPY %sext | ||
... | ||
|
||
--- | ||
name: trunc_s8_inreg_16 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0: | ||
liveins: $vgpr0 | ||
; CHECK-LABEL: name: trunc_s8_inreg_16 | ||
; CHECK: liveins: $vgpr0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: %copy:_(s32) = COPY $vgpr0 | ||
; CHECK-NEXT: %inreg:_(s32) = G_SEXT_INREG %copy, 16 | ||
; CHECK-NEXT: %trunc:_(s8) = G_TRUNC %inreg(s32) | ||
; CHECK-NEXT: %sext:_(s32) = G_SEXT %trunc(s8) | ||
; CHECK-NEXT: $vgpr0 = COPY %sext(s32) | ||
%copy:_(s32) = COPY $vgpr0 | ||
%inreg:_(s32) = G_SEXT_INREG %copy, 16 | ||
%trunc:_(s8) = G_TRUNC %inreg | ||
%sext:_(s32) = G_SEXT %trunc | ||
$vgpr0 = COPY %sext | ||
... | ||
|
||
# TODO?: We could handle this by inserting a trunc, but I'm not sure how useful that'd be. | ||
--- | ||
name: mismatching_types | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0: | ||
liveins: $vgpr0 | ||
; CHECK-LABEL: name: mismatching_types | ||
; CHECK: liveins: $vgpr0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: %copy:_(s32) = COPY $vgpr0 | ||
; CHECK-NEXT: %inreg:_(s32) = G_SEXT_INREG %copy, 8 | ||
; CHECK-NEXT: %trunc:_(s8) = G_TRUNC %inreg(s32) | ||
; CHECK-NEXT: %sext:_(s16) = G_SEXT %trunc(s8) | ||
; CHECK-NEXT: %anyext:_(s32) = G_ANYEXT %sext(s16) | ||
; CHECK-NEXT: $vgpr0 = COPY %anyext(s32) | ||
%copy:_(s32) = COPY $vgpr0 | ||
%inreg:_(s32) = G_SEXT_INREG %copy, 8 | ||
%trunc:_(s8) = G_TRUNC %inreg | ||
%sext:_(s16) = G_SEXT %trunc | ||
%anyext:_(s32) = G_ANYEXT %sext | ||
$vgpr0 = COPY %anyext | ||
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You also need to check that
$sir
and$dst
have the same width, right?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.
GIReplaceReg
implicitly does it. It'll checkcanReplaceReg
There is one testcase that has different widths that shows it working
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.
That seems like a weird design. Surely all the checking of conditions should be done in the "match" part? I didn't even know that an "apply" function was allowed to fail.
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.
apply should not be allowed to fail
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.
On a related note, couldn't you split this whole combine into two independently useful parts:
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.
Apply isn't allowed to fail. It's just that the presence of
GIReplaceReg
triggers emission of acanReplaceReg
call during the matching portion of the match table rule.Good idea, I can try that
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.
... or maybe we should remove the distinction between the match and apply parts as previously discussed.