Skip to content

Commit 31e4363

Browse files
nikicdyung
authored andcommitted
[NVPTX] Disable relative lookup tables (#159748)
Relative lookup tables result in "LLVM ERROR: Circular dependency found in global variable set", so disable them for this target. (cherry picked from commit 1ed1537)
1 parent 74cb34a commit 31e4363

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ class NVPTXTTIImpl final : public BasicTTIImplBase<NVPTXTTIImpl> {
183183
void collectKernelLaunchBounds(
184184
const Function &F,
185185
SmallVectorImpl<std::pair<StringRef, int64_t>> &LB) const override;
186+
187+
bool shouldBuildRelLookupTables() const override {
188+
// Self-referential globals are not supported.
189+
return false;
190+
}
186191
};
187192

188193
} // end namespace llvm
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
2+
; RUN: opt < %s -passes=rel-lookup-table-converter -relocation-model=pic -S | FileCheck %s
3+
; REQUIRES: nvptx-registered-target
4+
target triple = "nvptx64-nvidia-cuda"
5+
6+
; Do not produce relative lookup table for nvptx target.
7+
8+
@a1 = internal constant i32 0, align 4
9+
@b1 = internal constant i32 0, align 4
10+
@c1 = internal constant i32 0, align 4
11+
@d1 = internal constant i32 0, align 4
12+
13+
@switch.table = private unnamed_addr constant [3 x ptr] [ptr @a1, ptr @b1, ptr @c1], align 8
14+
15+
;.
16+
; CHECK: @a1 = internal constant i32 0, align 4
17+
; CHECK: @b1 = internal constant i32 0, align 4
18+
; CHECK: @c1 = internal constant i32 0, align 4
19+
; CHECK: @d1 = internal constant i32 0, align 4
20+
; CHECK: @switch.table = private unnamed_addr constant [3 x ptr] [ptr @a1, ptr @b1, ptr @c1], align 8
21+
;.
22+
define ptr @internal_linkage(i32 %cond) {
23+
; CHECK-LABEL: define ptr @internal_linkage(
24+
; CHECK-SAME: i32 [[COND:%.*]]) {
25+
; CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [3 x ptr], ptr @switch.table, i32 0, i32 [[COND]]
26+
; CHECK-NEXT: [[RELTABLE_INTRINSIC:%.*]] = load ptr, ptr [[SWITCH_GEP]], align 8
27+
; CHECK-NEXT: ret ptr [[RELTABLE_INTRINSIC]]
28+
;
29+
%switch.gep = getelementptr inbounds [3 x ptr], ptr @switch.table, i32 0, i32 %cond
30+
%switch.load = load ptr, ptr %switch.gep, align 8
31+
ret ptr %switch.load
32+
}

0 commit comments

Comments
 (0)