-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[RISCV] Fold vp.reverse(vp.load(ADDR, MASK)) -> vp.strided.load(ADDR, -1, MASK). #123115
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0bbaf5
[RISCV] Fold vp.reverse(vp.load(ADDR, MASK)) -> vp.strided.load(ADDR,…
topperc 58dadc9
fixup! remove undef from tests.
topperc e045e5d
Update llvm/lib/Target/RISCV/RISCVISelLowering.cpp
topperc 167e6a9
fixup! address review comment.
topperc 4c4232f
fixup! improve comments
topperc 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
| ; RUN: llc -mtriple=riscv64 -mattr=+f,+v -verify-machineinstrs < %s | FileCheck %s | ||
|
|
||
| define <vscale x 2 x float> @test_reverse_load_combiner(<vscale x 2 x float>* %ptr, i32 zeroext %evl) { | ||
| ; CHECK-LABEL: test_reverse_load_combiner: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: slli a2, a1, 2 | ||
| ; CHECK-NEXT: add a0, a2, a0 | ||
| ; CHECK-NEXT: addi a0, a0, -4 | ||
| ; CHECK-NEXT: li a2, -4 | ||
| ; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, ma | ||
| ; CHECK-NEXT: vlse32.v v8, (a0), a2 | ||
| ; CHECK-NEXT: ret | ||
| %load = call <vscale x 2 x float> @llvm.vp.load.nxv2f32.p0nxv2f32(<vscale x 2 x float>* %ptr, <vscale x 2 x i1> splat (i1 true), i32 %evl) | ||
| %rev = call <vscale x 2 x float> @llvm.experimental.vp.reverse.nxv2f32(<vscale x 2 x float> %load, <vscale x 2 x i1> splat (i1 true), i32 %evl) | ||
| ret <vscale x 2 x float> %rev | ||
| } | ||
|
|
||
| define <vscale x 2 x float> @test_load_mask_is_vp_reverse(<vscale x 2 x float>* %ptr, <vscale x 2 x i1> %mask, i32 zeroext %evl) { | ||
| ; CHECK-LABEL: test_load_mask_is_vp_reverse: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: slli a2, a1, 2 | ||
| ; CHECK-NEXT: add a0, a2, a0 | ||
| ; CHECK-NEXT: addi a0, a0, -4 | ||
| ; CHECK-NEXT: li a2, -4 | ||
| ; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, ma | ||
| ; CHECK-NEXT: vlse32.v v8, (a0), a2, v0.t | ||
| ; CHECK-NEXT: ret | ||
| %loadmask = call <vscale x 2 x i1> @llvm.experimental.vp.reverse.nxv2i1(<vscale x 2 x i1> %mask, <vscale x 2 x i1> splat (i1 true), i32 %evl) | ||
| %load = call <vscale x 2 x float> @llvm.vp.load.nxv2f32.p0nxv2f32(<vscale x 2 x float>* %ptr, <vscale x 2 x i1> %loadmask, i32 %evl) | ||
| %rev = call <vscale x 2 x float> @llvm.experimental.vp.reverse.nxv2f32(<vscale x 2 x float> %load, <vscale x 2 x i1> splat (i1 true), i32 %evl) | ||
| ret <vscale x 2 x float> %rev | ||
| } | ||
|
|
||
| define <vscale x 2 x float> @test_load_mask_not_all_one(<vscale x 2 x float>* %ptr, <vscale x 2 x i1> %notallones, i32 zeroext %evl) { | ||
| ; CHECK-LABEL: test_load_mask_not_all_one: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, ma | ||
| ; CHECK-NEXT: vle32.v v9, (a0), v0.t | ||
| ; CHECK-NEXT: vid.v v8, v0.t | ||
| ; CHECK-NEXT: addi a1, a1, -1 | ||
| ; CHECK-NEXT: vrsub.vx v10, v8, a1, v0.t | ||
| ; CHECK-NEXT: vrgather.vv v8, v9, v10, v0.t | ||
| ; CHECK-NEXT: ret | ||
| %load = call <vscale x 2 x float> @llvm.vp.load.nxv2f32.p0nxv2f32(<vscale x 2 x float>* %ptr, <vscale x 2 x i1> %notallones, i32 %evl) | ||
| %rev = call <vscale x 2 x float> @llvm.experimental.vp.reverse.nxv2f32(<vscale x 2 x float> %load, <vscale x 2 x i1> %notallones, i32 %evl) | ||
| ret <vscale x 2 x float> %rev | ||
| } | ||
|
|
||
| define <vscale x 2 x float> @test_different_evl(<vscale x 2 x float>* %ptr, <vscale x 2 x i1> %mask, i32 zeroext %evl1, i32 zeroext %evl2) { | ||
| ; CHECK-LABEL: test_different_evl: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: addi a3, a1, -1 | ||
| ; CHECK-NEXT: vsetvli zero, a1, e16, mf2, ta, ma | ||
| ; CHECK-NEXT: vid.v v8 | ||
| ; CHECK-NEXT: vsetvli zero, zero, e8, mf4, ta, ma | ||
| ; CHECK-NEXT: vmv.v.i v9, 0 | ||
| ; CHECK-NEXT: vsetvli zero, zero, e16, mf2, ta, ma | ||
| ; CHECK-NEXT: vrsub.vx v8, v8, a3 | ||
| ; CHECK-NEXT: vsetvli zero, zero, e8, mf4, ta, ma | ||
| ; CHECK-NEXT: vmerge.vim v9, v9, 1, v0 | ||
| ; CHECK-NEXT: vrgatherei16.vv v10, v9, v8 | ||
| ; CHECK-NEXT: vmsne.vi v0, v10, 0 | ||
| ; CHECK-NEXT: vsetvli zero, a2, e32, m1, ta, ma | ||
| ; CHECK-NEXT: vle32.v v9, (a0), v0.t | ||
| ; CHECK-NEXT: addi a2, a2, -1 | ||
| ; CHECK-NEXT: vid.v v8 | ||
| ; CHECK-NEXT: vrsub.vx v10, v8, a2 | ||
| ; CHECK-NEXT: vrgather.vv v8, v9, v10 | ||
| ; CHECK-NEXT: ret | ||
| %loadmask = call <vscale x 2 x i1> @llvm.experimental.vp.reverse.nxv2i1(<vscale x 2 x i1> %mask, <vscale x 2 x i1> splat (i1 true), i32 %evl1) | ||
| %load = call <vscale x 2 x float> @llvm.vp.load.nxv2f32.p0nxv2f32(<vscale x 2 x float>* %ptr, <vscale x 2 x i1> %loadmask, i32 %evl2) | ||
| %rev = call <vscale x 2 x float> @llvm.experimental.vp.reverse.nxv2f32(<vscale x 2 x float> %load, <vscale x 2 x i1> splat (i1 true), i32 %evl2) | ||
| ret <vscale x 2 x float> %rev | ||
| } | ||
|
|
||
| declare <vscale x 2 x float> @llvm.vp.load.nxv2f32.p0nxv2f32(<vscale x 2 x float>* nocapture, <vscale x 2 x i1>, i32) | ||
| declare <vscale x 2 x float> @llvm.experimental.vp.reverse.nxv2f32(<vscale x 2 x float>, <vscale x 2 x i1>, i32) | ||
| declare <vscale x 2 x i1> @llvm.experimental.vp.reverse.nxv2i1(<vscale x 2 x i1>, <vscale x 2 x i1>, i32) |
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.
I don't really follow the value of this bit, but it's tested, and appears correct, so non-blocking.
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're asking about the mask being reversed? I believe the vectorizer can generate this for some mask predicated cases.
Uh oh!
There was an error while loading. Please reload this page.
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 meant more the vp.reverse of a all i1s vector is just an all 1s vector. Why we kept around the reverse and why this is useful to match here seem a bit odd. Again, non-blocking.
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.
We're not checking for a reverse of an all 1s mask. We're checking for an "unmasked" reverse of any mask. We're checking operand 1 of the reverse not operand 0.
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 think this is the same comment that I got confused about in #123123 (comment)
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've updated the comments. @lukel97 can you review again.