-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[DAGCombiner][RISCV] Handle truncating splats in isNeutralConstant #87338
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
lukel97
merged 3 commits into
llvm:main
from
lukel97:foldSelectWithIdentityConstant-truncated-splat
Apr 4, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,60 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4 | ||
; RUN: llc -mtriple=riscv32 -mattr=+v -verify-machineinstrs < %s | FileCheck %s | ||
; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s | FileCheck %s | ||
|
||
; The following binop x, (zext i1) tests will be vector-legalized into a vselect | ||
; of two splat_vectors, but on RV64 the splat value will be implicitly | ||
; truncated: | ||
; | ||
; t15: nxv2i32 = splat_vector Constant:i64<1> | ||
; t13: nxv2i32 = splat_vector Constant:i64<0> | ||
; t16: nxv2i32 = vselect t2, t15, t13 | ||
; t7: nxv2i32 = add t4, t16 | ||
; | ||
; Make sure that foldSelectWithIdentityConstant in DAGCombiner.cpp handles the | ||
; truncating splat, so we pull the vselect back and fold it into a mask. | ||
|
||
define <vscale x 2 x i32> @i1_zext_add(<vscale x 2 x i1> %a, <vscale x 2 x i32> %b) { | ||
; CHECK-LABEL: i1_zext_add: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu | ||
; CHECK-NEXT: vadd.vi v8, v8, 1, v0.t | ||
; CHECK-NEXT: ret | ||
%zext = zext <vscale x 2 x i1> %a to <vscale x 2 x i32> | ||
%add = add <vscale x 2 x i32> %b, %zext | ||
ret <vscale x 2 x i32> %add | ||
} | ||
|
||
define <vscale x 2 x i32> @i1_zext_add_commuted(<vscale x 2 x i1> %a, <vscale x 2 x i32> %b) { | ||
; CHECK-LABEL: i1_zext_add_commuted: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu | ||
; CHECK-NEXT: vadd.vi v8, v8, 1, v0.t | ||
; CHECK-NEXT: ret | ||
%zext = zext <vscale x 2 x i1> %a to <vscale x 2 x i32> | ||
%add = add <vscale x 2 x i32> %zext, %b | ||
ret <vscale x 2 x i32> %add | ||
} | ||
|
||
define <vscale x 2 x i32> @i1_zext_sub(<vscale x 2 x i1> %a, <vscale x 2 x i32> %b) { | ||
; CHECK-LABEL: i1_zext_sub: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: li a0, 1 | ||
; CHECK-NEXT: vsetvli a1, zero, e32, m1, ta, mu | ||
; CHECK-NEXT: vsub.vx v8, v8, a0, v0.t | ||
; CHECK-NEXT: ret | ||
%zext = zext <vscale x 2 x i1> %a to <vscale x 2 x i32> | ||
%sub = sub <vscale x 2 x i32> %b, %zext | ||
ret <vscale x 2 x i32> %sub | ||
} | ||
|
||
define <vscale x 2 x i32> @i1_zext_or(<vscale x 2 x i1> %a, <vscale x 2 x i32> %b) { | ||
; CHECK-LABEL: i1_zext_or: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu | ||
; CHECK-NEXT: vor.vi v8, v8, 1, v0.t | ||
; CHECK-NEXT: ret | ||
%zext = zext <vscale x 2 x i1> %a to <vscale x 2 x i32> | ||
%or = or <vscale x 2 x i32> %b, %zext | ||
ret <vscale x 2 x i32> %or | ||
} |
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.
Can you add some tests for smax/smin?
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 tried but I couldn't think of how to. We need to create a splat_vector that implicitly truncates, but if you create it via a regular splat in IR it will arrive in SelectionDAG with a matching type.
It will eventually get type legalized to a truncating splat_vector but by then the fold will have already happened in the first round of DAG combine:
Hence why the tests are in that zext form, since they get created during vector legalization. But the zext form only allows us to choose constants of zero or one.
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.
combineBinOpToReduce
also usesisNeutralConstant
.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.
It looks like it also runs before type legalization so I presume it will have the same issue