Skip to content

Commit 53d33d3

Browse files
shiltianmordante
andauthored
[Attributor] Fix an issue that an access is skipped by mistake (llvm#101862)
When we check if an access can be skipped, there is a case that an inter-procedural interference access exists after a dominant write. Currently we rely on `AAInterFnReachability` to tell if the access can be reachable. If it is not, we can safely skip the access. However, it is based on an assumption that the AA exists. It is possible that the AA doesn't exist. In this case, we can't safely assume the acess can be skipped because we have to assume the access can reach. This can happen when `AAInterFnReachability` is not in the allowed AA list when creating the attributor, such as AMDGPUAttributor. Co-authored-by: Mark de Wever <[email protected]>
1 parent 0395868 commit 53d33d3

File tree

2 files changed

+87
-14
lines changed

2 files changed

+87
-14
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,20 +1325,20 @@ struct AAPointerInfoImpl
13251325

13261326
const auto *FnReachabilityAA = A.getAAFor<AAInterFnReachability>(
13271327
QueryingAA, IRPosition::function(Scope), DepClassTy::OPTIONAL);
1328-
1329-
// Without going backwards in the call tree, can we reach the access
1330-
// from the least dominating write. Do not allow to pass the instruction
1331-
// itself either.
1332-
bool Inserted = ExclusionSet.insert(&I).second;
1333-
1334-
if (!FnReachabilityAA ||
1335-
!FnReachabilityAA->instructionCanReach(
1336-
A, *LeastDominatingWriteInst,
1337-
*Acc.getRemoteInst()->getFunction(), &ExclusionSet))
1338-
WriteChecked = true;
1339-
1340-
if (Inserted)
1341-
ExclusionSet.erase(&I);
1328+
if (FnReachabilityAA) {
1329+
// Without going backwards in the call tree, can we reach the access
1330+
// from the least dominating write. Do not allow to pass the
1331+
// instruction itself either.
1332+
bool Inserted = ExclusionSet.insert(&I).second;
1333+
1334+
if (!FnReachabilityAA->instructionCanReach(
1335+
A, *LeastDominatingWriteInst,
1336+
*Acc.getRemoteInst()->getFunction(), &ExclusionSet))
1337+
WriteChecked = true;
1338+
1339+
if (Inserted)
1340+
ExclusionSet.erase(&I);
1341+
}
13421342
}
13431343

13441344
if (ReadChecked && WriteChecked)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals
2+
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-attributor %s -o - | FileCheck %s
3+
4+
@g_fn = addrspace(1) global ptr null
5+
6+
;.
7+
; CHECK: @g_fn = addrspace(1) global ptr null
8+
;.
9+
define void @set_fn(ptr %fn) {
10+
; CHECK-LABEL: define {{[^@]+}}@set_fn
11+
; CHECK-SAME: (ptr [[FN:%.*]]) #[[ATTR0:[0-9]+]] {
12+
; CHECK-NEXT: entry:
13+
; CHECK-NEXT: store ptr [[FN]], ptr addrspace(1) @g_fn, align 8
14+
; CHECK-NEXT: ret void
15+
;
16+
entry:
17+
store ptr %fn, ptr addrspace(1) @g_fn
18+
ret void
19+
}
20+
21+
define void @get_fn(ptr %fn) {
22+
; CHECK-LABEL: define {{[^@]+}}@get_fn
23+
; CHECK-SAME: (ptr [[FN:%.*]]) #[[ATTR0]] {
24+
; CHECK-NEXT: entry:
25+
; CHECK-NEXT: [[LOAD:%.*]] = load ptr, ptr addrspace(1) @g_fn, align 8
26+
; CHECK-NEXT: store ptr [[LOAD]], ptr [[FN]], align 8
27+
; CHECK-NEXT: ret void
28+
;
29+
entry:
30+
%load = load ptr, ptr addrspace(1) @g_fn
31+
store ptr %load, ptr %fn
32+
ret void
33+
}
34+
35+
define void @foo() {
36+
; CHECK-LABEL: define {{[^@]+}}@foo
37+
; CHECK-SAME: () #[[ATTR1:[0-9]+]] {
38+
; CHECK-NEXT: entry:
39+
; CHECK-NEXT: [[FN:%.*]] = alloca ptr, align 8, addrspace(5)
40+
; CHECK-NEXT: store ptr null, ptr addrspace(5) [[FN]], align 8
41+
; CHECK-NEXT: [[FN_CAST:%.*]] = addrspacecast ptr addrspace(5) [[FN]] to ptr
42+
; CHECK-NEXT: call void @get_fn(ptr [[FN_CAST]])
43+
; CHECK-NEXT: [[LOAD:%.*]] = load ptr, ptr addrspace(5) [[FN]], align 8
44+
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne ptr [[LOAD]], null
45+
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
46+
; CHECK: if.then:
47+
; CHECK-NEXT: [[LOAD_1:%.*]] = load ptr, ptr addrspace(5) [[FN]], align 8
48+
; CHECK-NEXT: call void [[LOAD_1]]()
49+
; CHECK-NEXT: br label [[IF_END]]
50+
; CHECK: if.end:
51+
; CHECK-NEXT: ret void
52+
;
53+
entry:
54+
%fn = alloca ptr, addrspace(5)
55+
store ptr null, ptr addrspace(5) %fn
56+
%fn.cast = addrspacecast ptr addrspace(5) %fn to ptr
57+
call void @get_fn(ptr %fn.cast)
58+
%load = load ptr, ptr addrspace(5) %fn
59+
%tobool = icmp ne ptr %load, null
60+
br i1 %tobool, label %if.then, label %if.end
61+
62+
if.then:
63+
%load.1 = load ptr, ptr addrspace(5) %fn
64+
call void %load.1()
65+
br label %if.end
66+
67+
if.end:
68+
ret void
69+
}
70+
;.
71+
; CHECK: attributes #[[ATTR0]] = { "amdgpu-no-agpr" "amdgpu-no-completion-action" "amdgpu-no-default-queue" "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-implicitarg-ptr" "amdgpu-no-lds-kernel-id" "amdgpu-no-multigrid-sync-arg" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" "amdgpu-waves-per-eu"="4,10" "uniform-work-group-size"="false" }
72+
; CHECK: attributes #[[ATTR1]] = { "amdgpu-waves-per-eu"="4,10" "uniform-work-group-size"="false" }
73+
;.

0 commit comments

Comments
 (0)