-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[GlobalISel] Widen vector loads from aligned ptrs #144309
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
Open
davemgreen
wants to merge
2
commits into
llvm:main
Choose a base branch
from
davemgreen:gh-gi-unalignedvecload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4072,6 +4072,19 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerLoad(GAnyLoad &LoadMI) { | |
if (MemTy != DstTy) | ||
return UnableToLegalize; | ||
|
||
Align Alignment = LoadMI.getAlign(); | ||
if (Alignment.value() * 8 > MemSizeInBits && | ||
isPowerOf2_64(DstTy.getScalarSizeInBits())) { | ||
LLT MoreTy = LLT::fixed_vector(NextPowerOf2(DstTy.getNumElements()), | ||
DstTy.getElementType()); | ||
MachineMemOperand *NewMMO = MF.getMachineMemOperand(&MMO, 0, MoreTy); | ||
auto NewLoad = MIRBuilder.buildLoad(MoreTy, PtrReg, *NewMMO); | ||
Comment on lines
+4075
to
+4081
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should have a short comment to explain the code for future readers. |
||
MIRBuilder.buildDeleteTrailingVectorElements(LoadMI.getReg(0), | ||
NewLoad.getReg(0)); | ||
LoadMI.eraseFromParent(); | ||
return Legalized; | ||
} | ||
|
||
// TODO: We can do better than scalarizing the vector and at least split it | ||
// in half. | ||
return reduceLoadStoreWidth(LoadMI, 0, DstTy.getElementType()); | ||
|
46 changes: 46 additions & 0 deletions
46
llvm/test/CodeGen/AArch64/GlobalISel/legalize-load-range.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,46 @@ | ||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5 | ||
# RUN: llc -mtriple=aarch64 -run-pass=legalizer -global-isel -o - %s | FileCheck %s | ||
|
||
--- | | ||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" | ||
target triple = "aarch64" | ||
|
||
define <3 x i16> @range_v3i16(ptr %a_ptr, ptr %b_ptr) { | ||
%a = load <3 x i16>, ptr %a_ptr, align 8, !range !0, !noundef !1 | ||
%b = load <3 x i16>, ptr %b_ptr, align 8, !range !2, !noundef !1 | ||
%result = add <3 x i16> %a, %b | ||
ret <3 x i16> %result | ||
} | ||
|
||
!0 = !{i16 16, i16 17} | ||
!1 = !{} | ||
!2 = !{i16 32, i16 33} | ||
... | ||
--- | ||
name: range_v3i16 | ||
body: | | ||
bb.1 (%ir-block.0): | ||
liveins: $x0, $x1 | ||
; Make sure we drop the range metadata when widening an aligned load. | ||
|
||
; CHECK-LABEL: name: range_v3i16 | ||
; CHECK: liveins: $x0, $x1 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x0 | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(p0) = COPY $x1 | ||
; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(<4 x s16>) = G_LOAD [[COPY]](p0) :: (load (<4 x s16>) from %ir.a_ptr) | ||
; CHECK-NEXT: [[LOAD1:%[0-9]+]]:_(<4 x s16>) = G_LOAD [[COPY1]](p0) :: (load (<4 x s16>) from %ir.b_ptr) | ||
; CHECK-NEXT: [[ADD:%[0-9]+]]:_(<4 x s16>) = G_ADD [[LOAD]], [[LOAD1]] | ||
; CHECK-NEXT: $d0 = COPY [[ADD]](<4 x s16>) | ||
; CHECK-NEXT: RET_ReallyLR implicit $d0 | ||
%0:_(p0) = COPY $x0 | ||
%1:_(p0) = COPY $x1 | ||
%2:_(<3 x s16>) = G_LOAD %0(p0) :: (load (<3 x s16>) from %ir.a_ptr, align 8, !range !0) | ||
%3:_(<3 x s16>) = G_LOAD %1(p0) :: (load (<3 x s16>) from %ir.b_ptr, align 8, !range !2) | ||
%4:_(<3 x s16>) = G_ADD %2, %3 | ||
%5:_(s16), %6:_(s16), %7:_(s16) = G_UNMERGE_VALUES %4(<3 x s16>) | ||
%8:_(s16) = G_IMPLICIT_DEF | ||
%9:_(<4 x s16>) = G_BUILD_VECTOR %5(s16), %6(s16), %7(s16), %8(s16) | ||
$d0 = COPY %9(<4 x s16>) | ||
RET_ReallyLR implicit $d0 | ||
... |
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
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
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.
Do you need to clear range metadata? It no longer applies to the widened elements
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 have added a test - it looks like when creating a MMO from another it does not copy the range metadata.