-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[AMDGPU] Apply alignment attr for make.buffer.rsrc #166914
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
Shoreshen
wants to merge
11
commits into
llvm:main
Choose a base branch
from
Shoreshen:add-align-for-make.buffer-intrinsic-v2
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
11 commits
Select commit
Hold shift + click to select a range
4d3d6e4
Apply alignment attr for make.buffer.rsrc
Shoreshen 505426b
fix format error
Shoreshen 4245ca5
Merge branch 'main' into add-align-for-make.buffer-intrinsic-v2
Shoreshen 07415ef
Merge branch 'main' into add-align-for-make.buffer-intrinsic-v2
Shoreshen 841bbe5
Merge branch 'main' into add-align-for-make.buffer-intrinsic-v2
Shoreshen 7be66a0
Addr 0 should have max alignment
Shoreshen 5efe07b
Move to amd specific attribute
Shoreshen 9d04645
fix failed test
Shoreshen 5e3479c
Merge branch 'main' into add-align-for-make.buffer-intrinsic-v2
Shoreshen 0da0b42
Merge branch 'main' into add-align-for-make.buffer-intrinsic-v2
Shoreshen 533ca2f
Merge branch 'main' into add-align-for-make.buffer-intrinsic-v2
Shoreshen 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 |
|---|---|---|
|
|
@@ -1584,6 +1584,117 @@ AAAMDGPUClusterDims::createForPosition(const IRPosition &IRP, Attributor &A) { | |
| llvm_unreachable("AAAMDGPUClusterDims is only valid for function position"); | ||
| } | ||
|
|
||
| struct AAAMDGPUMakeBufferRsrcAlign | ||
| : public IRAttribute< | ||
| Attribute::Alignment, | ||
| StateWrapper<IncIntegerState<uint64_t, Value::MaximumAlignment, 1>, | ||
| AbstractAttribute>, | ||
| AAAMDGPUMakeBufferRsrcAlign> { | ||
| using Base = IRAttribute< | ||
| Attribute::Alignment, | ||
| StateWrapper<IncIntegerState<uint64_t, Value::MaximumAlignment, 1>, | ||
| AbstractAttribute>, | ||
| AAAMDGPUMakeBufferRsrcAlign>; | ||
|
|
||
| AAAMDGPUMakeBufferRsrcAlign(const IRPosition &IRP, Attributor &A) | ||
| : Base(IRP) {} | ||
|
|
||
| void initialize(Attributor &A) override {} | ||
|
|
||
| ChangeStatus updateImpl(Attributor &A) override { | ||
| Instruction *I = getIRPosition().getCtxI(); | ||
| const auto *AlignAA = A.getAAFor<AAAlign>( | ||
| *this, IRPosition::value(*(I->getOperand(0))), DepClassTy::REQUIRED); | ||
| if (AlignAA) | ||
| return clampStateAndIndicateChange<StateType>( | ||
| this->getState(), AlignAA->getAssumedAlign().value()); | ||
|
|
||
| return indicatePessimisticFixpoint(); | ||
| } | ||
|
|
||
| /// Create an abstract attribute view for the position \p IRP. | ||
| static AAAMDGPUMakeBufferRsrcAlign &createForPosition(const IRPosition &IRP, | ||
| Attributor &A) { | ||
| if (IRP.getPositionKind() == IRPosition::IRP_CALL_SITE_RETURNED) | ||
| if (Instruction *I = dyn_cast<Instruction>(&IRP.getAssociatedValue())) | ||
| if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) | ||
| if (II->getIntrinsicID() == Intrinsic::amdgcn_make_buffer_rsrc) | ||
| return *new (A.Allocator) AAAMDGPUMakeBufferRsrcAlign(IRP, A); | ||
| llvm_unreachable("AAAMDGPUMakeBufferRsrcAlign is only valid for call site " | ||
| "return position on make.buffer.rsrc intrinsic"); | ||
| } | ||
|
|
||
| // Manifest users | ||
| ChangeStatus manifest(Attributor &A) override { | ||
| ChangeStatus Changed = ChangeStatus::UNCHANGED; | ||
|
|
||
| // Check for users that allow alignment annotations. | ||
| Value &AssociatedValue = getAssociatedValue(); | ||
| if (isa<ConstantData>(AssociatedValue)) | ||
| return ChangeStatus::UNCHANGED; | ||
|
|
||
| for (const Use &U : AssociatedValue.uses()) { | ||
| if (auto *SI = dyn_cast<StoreInst>(U.getUser())) { | ||
| if (SI->getPointerOperand() == &AssociatedValue) { | ||
| if (SI->getAlign() > getAssumedAlign()) { | ||
| SI->setAlignment(getAssumedAlign()); | ||
| Changed = ChangeStatus::CHANGED; | ||
| } | ||
| } | ||
| } else if (auto *LI = dyn_cast<LoadInst>(U.getUser())) { | ||
| if (LI->getPointerOperand() == &AssociatedValue) { | ||
| if (LI->getAlign() > getAssumedAlign()) { | ||
| LI->setAlignment(getAssumedAlign()); | ||
| Changed = ChangeStatus::CHANGED; | ||
| } | ||
| } | ||
| } else if (auto *RMW = dyn_cast<AtomicRMWInst>(U.getUser())) { | ||
| if (RMW->getAlign() > getAssumedAlign()) { | ||
| RMW->setAlignment(getAssumedAlign()); | ||
| Changed = ChangeStatus::CHANGED; | ||
| } | ||
| } else if (auto *CAS = dyn_cast<AtomicCmpXchgInst>(U.getUser())) { | ||
| if (CAS->getAlign() > getAssumedAlign()) { | ||
| CAS->setAlignment(getAssumedAlign()); | ||
| Changed = ChangeStatus::CHANGED; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Manifest intrinsic it self | ||
| Changed |= Base::manifest(A); | ||
|
|
||
| return Changed; | ||
| } | ||
|
|
||
| StringRef getName() const override { return "AAAMDGPUMakeBufferRsrcAlign"; } | ||
|
|
||
| const std::string getAsStr(Attributor *) const override { | ||
| std::string Buffer = "AAAMDGPUMakeBufferRsrcAlign["; | ||
| raw_string_ostream OS(Buffer); | ||
| OS << getState().getKnown() << ',' << getState().getAssumed() << ']'; | ||
| return OS.str(); | ||
| } | ||
|
|
||
| const char *getIdAddr() const override { return &ID; } | ||
|
|
||
| void trackStatistics() const override {} | ||
|
|
||
| Align getAssumedAlign() const { return Align(getAssumed()); } | ||
|
|
||
| void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, | ||
| SmallVectorImpl<Attribute> &Attrs) const override { | ||
| if (getAssumedAlign() > 1) | ||
| Attrs.emplace_back( | ||
| Attribute::getWithAlignment(Ctx, Align(getAssumedAlign()))); | ||
| } | ||
|
|
||
| /// Unique ID (due to the unique address) | ||
| static const char ID; | ||
| }; | ||
|
|
||
| const char AAAMDGPUMakeBufferRsrcAlign::ID = 0; | ||
|
|
||
| static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM, | ||
| AMDGPUAttributorOptions Options, | ||
| ThinOrFullLTOPhase LTOPhase) { | ||
|
|
@@ -1603,7 +1714,8 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM, | |
| &AAAMDGPUMinAGPRAlloc::ID, &AACallEdges::ID, &AAPointerInfo::ID, | ||
| &AAPotentialConstantValues::ID, &AAUnderlyingObjects::ID, | ||
| &AANoAliasAddrSpace::ID, &AAAddressSpace::ID, &AAIndirectCallInfo::ID, | ||
| &AAAMDGPUClusterDims::ID}); | ||
| &AAAMDGPUClusterDims::ID, &AAAlign::ID, | ||
| &AAAMDGPUMakeBufferRsrcAlign::ID}); | ||
|
|
||
| AttributorConfig AC(CGUpdater); | ||
| AC.IsClosedWorldModule = Options.IsClosedWorld; | ||
|
|
@@ -1657,6 +1769,10 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM, | |
| Ptr = RMW->getPointerOperand(); | ||
| else if (auto *CmpX = dyn_cast<AtomicCmpXchgInst>(&I)) | ||
| Ptr = CmpX->getPointerOperand(); | ||
| else if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I)) | ||
| if (II->getIntrinsicID() == Intrinsic::amdgcn_make_buffer_rsrc) | ||
| A.getOrCreateAAFor<AAAMDGPUMakeBufferRsrcAlign>( | ||
|
Contributor
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. The creation of the AA is weird here as well. I'd expect that we want to know the alignment of a load/store instruction, and we see the pointer is a buffer pointer, then we do something. Here it looks like it is completely up side down. |
||
| IRPosition::value(*II)); | ||
|
|
||
| if (Ptr) { | ||
| A.getOrCreateAAFor<AAAddressSpace>(IRPosition::value(*Ptr)); | ||
|
|
||
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,26 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 | ||
| ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-attributor %s -o - | FileCheck %s | ||
|
|
||
| define float @load_gt_base(ptr align 4 %p) { | ||
| ; CHECK-LABEL: define float @load_gt_base( | ||
| ; CHECK-SAME: ptr align 4 [[P:%.*]]) #[[ATTR0:[0-9]+]] { | ||
| ; CHECK-NEXT: [[PTR:%.*]] = call align 4 ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p0(ptr align 4 [[P]], i16 0, i64 0, i32 0) | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = load float, ptr addrspace(7) [[PTR]], align 4 | ||
| ; CHECK-NEXT: ret float [[LOADED]] | ||
| ; | ||
| %ptr = call ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p0(ptr %p, i16 0, i64 0, i32 0) | ||
| %loaded = load float, ptr addrspace(7) %ptr, align 8 | ||
| ret float %loaded | ||
| } | ||
|
|
||
| define float @load_lt_base(ptr align 8 %p) { | ||
| ; CHECK-LABEL: define float @load_lt_base( | ||
| ; CHECK-SAME: ptr align 8 [[P:%.*]]) #[[ATTR0]] { | ||
| ; CHECK-NEXT: [[PTR:%.*]] = call align 8 ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p0(ptr align 8 [[P]], i16 0, i64 0, i32 0) | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = load float, ptr addrspace(7) [[PTR]], align 4 | ||
| ; CHECK-NEXT: ret float [[LOADED]] | ||
| ; | ||
| %ptr = call ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p0(ptr %p, i16 0, i64 0, i32 0) | ||
| %loaded = load float, ptr addrspace(7) %ptr, align 4 | ||
| ret float %loaded | ||
| } |
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'd make it something like
AAAMDGPUAlign, and then use it to deal with all AMDGPU related alignments.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.
Also, document the new class.