-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[AMDGPU] Add alignment attr & propagate alignment through make.buffer.rsrc inst #145278
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
base: main
Are you sure you want to change the base?
Changes from all commits
888df54
122a2f7
598533b
806dfca
ce9453b
e950014
dafa6df
fb747b8
af05cac
1c9c512
9ec3058
de979f9
9d5af0c
e8fba9e
401f403
f81c4b2
2af8229
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1356,8 +1356,15 @@ struct InformationCache { | |
/// Return the flat address space if the associated target has. | ||
LLVM_ABI std::optional<unsigned> getFlatAddressSpace() const; | ||
|
||
virtual bool shouldTrackUse(const AbstractAttribute *QueryingAA, | ||
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. Why do we need this? 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. Hi @shiltian , this is used to forward propagate (which is in initialization of each AAAlign). When calling followUsesInMBEC if this returns true, it will put user's user into the list for checking known alignment |
||
Value &AssociatedValue, const Use *U, | ||
const Instruction *I) const { | ||
return false; | ||
} | ||
|
||
virtual unsigned getMaxAddrSpace() const { return ~0U; } | ||
|
||
|
||
private: | ||
struct FunctionInfo { | ||
LLVM_ABI ~FunctionInfo(); | ||
|
@@ -2045,6 +2052,19 @@ struct Attributor { | |
SimplificationCallbacks[IRP].emplace_back(CB); | ||
} | ||
|
||
using AlignmentCallbackTy = | ||
std::function<void(const IRPosition &, const AbstractAttribute *, | ||
SmallVectorImpl<AA::ValueAndContext> &)>; | ||
void registerAlignmentCallback(const IRPosition &IRP, | ||
const AlignmentCallbackTy &CB) { | ||
AlignmentCallBacks[IRP].emplace_back(CB); | ||
} | ||
|
||
SmallVector<AlignmentCallbackTy, 1> | ||
getAlignmentCallback(const IRPosition &IRP) { | ||
return AlignmentCallBacks.lookup(IRP); | ||
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. What if the lookup fails? I'd prefer to do similar style as the simplification CB. |
||
} | ||
|
||
/// Return true if there is a simplification callback for \p IRP. | ||
bool hasSimplificationCallback(const IRPosition &IRP) { | ||
return SimplificationCallbacks.count(IRP); | ||
|
@@ -2096,6 +2116,9 @@ struct Attributor { | |
DenseMap<IRPosition, SmallVector<SimplifictionCallbackTy, 1>> | ||
SimplificationCallbacks; | ||
|
||
/// The vector with AAAlign callbacks registered by outside AAs. | ||
DenseMap<IRPosition, SmallVector<AlignmentCallbackTy, 1>> AlignmentCallBacks; | ||
|
||
/// The vector with all simplification callbacks for global variables | ||
/// registered by outside AAs. | ||
DenseMap<const GlobalVariable *, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5204,6 +5204,10 @@ static unsigned getKnownAlignForUse(Attributor &A, AAAlign &QueryingAA, | |
TrackUse = true; | ||
return 0; | ||
} | ||
if (A.getInfoCache().shouldTrackUse(&QueryingAA, AssociatedValue, U, I)) { | ||
TrackUse = true; | ||
return 0; | ||
} | ||
|
||
MaybeAlign MA; | ||
if (const auto *CB = dyn_cast<CallBase>(I)) { | ||
|
@@ -5502,7 +5506,32 @@ struct AAAlignCallSiteReturned final | |
using Base = AACalleeToCallSite<AAAlign, AAAlignImpl>; | ||
AAAlignCallSiteReturned(const IRPosition &IRP, Attributor &A) | ||
: Base(IRP, A) {} | ||
ChangeStatus updateImpl(Attributor &A) override { | ||
SmallVector<AA::ValueAndContext> Values; | ||
SmallVector<Attributor::AlignmentCallbackTy, 1> AligmentCBs = | ||
A.getAlignmentCallback(getIRPosition()); | ||
|
||
for (Attributor::AlignmentCallbackTy CB : AligmentCBs) | ||
CB(getIRPosition(), this, Values); | ||
|
||
if (!Values.empty()) { | ||
StateType T; | ||
for (AA::ValueAndContext &VAC : Values) { | ||
const AAAlign *AA = A.getAAFor<AAAlign>( | ||
*this, IRPosition::value(*VAC.getValue()), DepClassTy::REQUIRED); | ||
if (AA && this != AA) { | ||
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. Not sure if that's a good idea to compare AA directly instead of comparing the associated value. |
||
const AAAlign::StateType &DS = AA->getState(); | ||
T ^= DS; | ||
} | ||
if (!T.isValidState()) | ||
return indicatePessimisticFixpoint(); | ||
} | ||
|
||
return clampStateAndIndicateChange(getState(), T); | ||
} | ||
|
||
return Base::updateImpl(A); | ||
} | ||
/// See AbstractAttribute::trackStatistics() | ||
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(align); } | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-attributor %s -o - | FileCheck %s | ||
|
||
define float @align_back_prop(ptr addrspace(1) align 4 %x) { | ||
; CHECK-LABEL: define float @align_back_prop( | ||
; CHECK-SAME: ptr addrspace(1) align 8 [[X:%.*]]) #[[ATTR0:[0-9]+]] { | ||
; CHECK-NEXT: [[FAT_PTR:%.*]] = call align 8 ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p1(ptr addrspace(1) [[X]], i16 0, i32 256, i32 0) | ||
; CHECK-NEXT: [[Y:%.*]] = load float, ptr addrspace(7) [[FAT_PTR]], align 8 | ||
; CHECK-NEXT: ret float [[Y]] | ||
; | ||
%fat.ptr = call ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p1(ptr addrspace(1) %x, i16 0, i32 256, i32 0) | ||
%y = load float, ptr addrspace(7) %fat.ptr, align 8 | ||
ret float %y | ||
} | ||
|
||
define float @align_foward_prop(ptr addrspace(1) align 8 %x) { | ||
; CHECK-LABEL: define float @align_foward_prop( | ||
; CHECK-SAME: ptr addrspace(1) align 8 [[X:%.*]]) #[[ATTR0]] { | ||
; CHECK-NEXT: [[FAT_PTR:%.*]] = call align 8 ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p1(ptr addrspace(1) [[X]], i16 0, i32 256, i32 0) | ||
; CHECK-NEXT: [[Y:%.*]] = load float, ptr addrspace(7) [[FAT_PTR]], align 8 | ||
; CHECK-NEXT: ret float [[Y]] | ||
; | ||
%fat.ptr = call ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p1(ptr addrspace(1) %x, i16 0, i32 256, i32 0) | ||
%y = load float, ptr addrspace(7) %fat.ptr, align 4 | ||
ret float %y | ||
} | ||
|
||
define float @align_mix_prop(ptr addrspace(1) align 4 %x) { | ||
; CHECK-LABEL: define float @align_mix_prop( | ||
; CHECK-SAME: ptr addrspace(1) align 8 [[X:%.*]]) #[[ATTR0]] { | ||
; CHECK-NEXT: [[FAT_PTR:%.*]] = call align 8 ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p1(ptr addrspace(1) [[X]], i16 0, i32 256, i32 0) | ||
; CHECK-NEXT: [[Y:%.*]] = load float, ptr addrspace(7) [[FAT_PTR]], align 8 | ||
; CHECK-NEXT: [[Z:%.*]] = load float, ptr addrspace(1) [[X]], align 8 | ||
; CHECK-NEXT: ret float [[Z]] | ||
; | ||
%fat.ptr = call ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p1(ptr addrspace(1) %x, i16 0, i32 256, i32 0) | ||
%y = load float, ptr addrspace(7) %fat.ptr, align 2 | ||
%z = load float, ptr addrspace(1) %x, align 8 | ||
ret float %z | ||
} |
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.
This value doesn't look 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.
Hi @shiltian , the first operand of this is 0 pointer
__builtin_amdgcn_make_buffer_rsrc((global void *)0LL, stride, num, flags);
, so the attribute regard it as the maximum alignment...