Skip to content

Commit ba87fba

Browse files
committed
[Attributor] Ignore different kernels for kernel lifetime objects
If a potential interfering access is in a different kernel and the underlying object has kernel lifetime we can straight out ignore the interfering access. TODO: This should be made much stronger via "reaching kernels", which we already track in AAKernelInfo.
1 parent bb96093 commit ba87fba

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,11 @@ struct AAPointerInfoImpl
12001200
A, this, IRPosition::function(Scope), DepClassTy::OPTIONAL,
12011201
IsKnownNoRecurse);
12021202

1203+
// TODO: Use reaching kernels from AAKernelInfo (or move it to
1204+
// AAExecutionDomain) such that we allow scopes other than kernels as long
1205+
// as the reaching kernels are disjoint.
1206+
bool InstInKernel = Scope.hasFnAttribute("kernel");
1207+
bool ObjHasKernelLifetime = false;
12031208
const bool UseDominanceReasoning =
12041209
FindInterferingWrites && IsKnownNoRecurse;
12051210
const DominatorTree *DT =
@@ -1232,6 +1237,7 @@ struct AAPointerInfoImpl
12321237
// If the alloca containing function is not recursive the alloca
12331238
// must be dead in the callee.
12341239
const Function *AIFn = AI->getFunction();
1240+
ObjHasKernelLifetime = AIFn->hasFnAttribute("kernel");
12351241
bool IsKnownNoRecurse;
12361242
if (AA::hasAssumedIRAttr<Attribute::NoRecurse>(
12371243
A, this, IRPosition::function(*AIFn), DepClassTy::OPTIONAL,
@@ -1241,7 +1247,8 @@ struct AAPointerInfoImpl
12411247
} else if (auto *GV = dyn_cast<GlobalValue>(&getAssociatedValue())) {
12421248
// If the global has kernel lifetime we can stop if we reach a kernel
12431249
// as it is "dead" in the (unknown) callees.
1244-
if (HasKernelLifetime(GV, *GV->getParent()))
1250+
ObjHasKernelLifetime = HasKernelLifetime(GV, *GV->getParent());
1251+
if (ObjHasKernelLifetime)
12451252
IsLiveInCalleeCB = [](const Function &Fn) {
12461253
return !Fn.hasFnAttribute("kernel");
12471254
};
@@ -1252,6 +1259,15 @@ struct AAPointerInfoImpl
12521259
AA::InstExclusionSetTy ExclusionSet;
12531260

12541261
auto AccessCB = [&](const Access &Acc, bool Exact) {
1262+
Function *AccScope = Acc.getRemoteInst()->getFunction();
1263+
bool AccInSameScope = AccScope == &Scope;
1264+
1265+
// If the object has kernel lifetime we can ignore accesses only reachable
1266+
// by other kernels. For now we only skip accesses *in* other kernels.
1267+
if (InstInKernel && ObjHasKernelLifetime && !AccInSameScope &&
1268+
AccScope->hasFnAttribute("kernel"))
1269+
return true;
1270+
12551271
if (Exact && Acc.isMustAccess() && Acc.getRemoteInst() != &I) {
12561272
if (Acc.isWrite() || (isa<LoadInst>(I) && Acc.isWriteOrAssumption()))
12571273
ExclusionSet.insert(Acc.getRemoteInst());
@@ -1262,8 +1278,7 @@ struct AAPointerInfoImpl
12621278
return true;
12631279

12641280
bool Dominates = FindInterferingWrites && DT && Exact &&
1265-
Acc.isMustAccess() &&
1266-
(Acc.getRemoteInst()->getFunction() == &Scope) &&
1281+
Acc.isMustAccess() && AccInSameScope &&
12671282
DT->dominates(Acc.getRemoteInst(), &I);
12681283
if (Dominates)
12691284
DominatingWrites.insert(&Acc);

llvm/test/Transforms/Attributor/value-simplify-gpu.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ define dso_local void @kernel3(i32 %C) norecurse "kernel" {
401401
; TUNIT-NEXT: [[I:%.*]] = icmp eq i32 [[C]], 42
402402
; TUNIT-NEXT: br i1 [[I]], label [[T:%.*]], label [[F:%.*]]
403403
; TUNIT: t:
404-
; TUNIT-NEXT: [[L:%.*]] = load i32, ptr addrspace(3) @AS3OneKernelAtATime, align 4
405-
; TUNIT-NEXT: call void @use(i32 noundef [[L]], i32 noundef [[L]], i32 noundef [[L]]) #[[ATTR7]]
404+
; TUNIT-NEXT: call void @use(i32 noundef 42, i32 noundef 42, i32 noundef 42) #[[ATTR7]]
406405
; TUNIT-NEXT: ret void
407406
; TUNIT: f:
408407
; TUNIT-NEXT: ret void
@@ -413,8 +412,7 @@ define dso_local void @kernel3(i32 %C) norecurse "kernel" {
413412
; CGSCC-NEXT: [[I:%.*]] = icmp eq i32 [[C]], 42
414413
; CGSCC-NEXT: br i1 [[I]], label [[T:%.*]], label [[F:%.*]]
415414
; CGSCC: t:
416-
; CGSCC-NEXT: [[L:%.*]] = load i32, ptr addrspace(3) @AS3OneKernelAtATime, align 4
417-
; CGSCC-NEXT: call void @use(i32 noundef [[L]], i32 noundef [[L]], i32 noundef [[L]]) #[[ATTR4]]
415+
; CGSCC-NEXT: call void @use(i32 noundef 42, i32 noundef 42, i32 noundef 42) #[[ATTR4]]
418416
; CGSCC-NEXT: ret void
419417
; CGSCC: f:
420418
; CGSCC-NEXT: ret void

0 commit comments

Comments
 (0)