Skip to content

Commit 8c53a8b

Browse files
committed
[Attributor] Fix an issue that an access is skipped by mistake
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.
1 parent 5c48f6f commit 8c53a8b

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ struct AAPointerInfoImpl
13311331
// itself either.
13321332
bool Inserted = ExclusionSet.insert(&I).second;
13331333

1334-
if (!FnReachabilityAA ||
1334+
if (FnReachabilityAA &&
13351335
!FnReachabilityAA->instructionCanReach(
13361336
A, *LeastDominatingWriteInst,
13371337
*Acc.getRemoteInst()->getFunction(), &ExclusionSet))
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)