Skip to content

Commit 48afa19

Browse files
KorovinVladigcbot
authored andcommitted
Allow all addrspace casts for @llvm.used
.
1 parent 1bfef8a commit 48afa19

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/ConstantEncoder.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2021-2023 Intel Corporation
3+
Copyright (C) 2021-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -93,6 +93,23 @@ encodeConstExprImpl(const IGCLLVM::AddrSpaceCastOperator &ASC,
9393
return {Data, Relocs};
9494
}
9595

96+
// The invalid addrspace conversions may appear in @llvm.used or
97+
// @llvm.compiler.used arrays until LLVM17: https://reviews.llvm.org/D144518.
98+
// Just skip them.
99+
bool IsOnlyInLLVMUsed = llvm::all_of(ASC.uses(), [](const Use &U) {
100+
const auto *C = dyn_cast<Constant>(U.getUser());
101+
if (!C)
102+
return false;
103+
return llvm::all_of(C->uses(), [](const Use &UU) {
104+
if (const auto *GV = dyn_cast<GlobalVariable>(UU.getUser()))
105+
return GV->getName() == "llvm.used" ||
106+
GV->getName() == "llvm.compiler.used";
107+
return false;
108+
});
109+
});
110+
if (IsOnlyInLLVMUsed)
111+
return {Data, Relocs};
112+
96113
vc::diagnose(
97114
ASC.getContext(), "ConstantEncoder",
98115
"such addrspacecast constant expression is not supported or illegal",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: llc %s -march=genx64 -mcpu=Gen9 -mattr=+ocl_runtime -vc-analyze=GenXOCLRuntimeInfo \
10+
; RUN: -vc-choose-pass-manager-override=false -o /dev/null 2>&1 | FileCheck %s
11+
12+
target datalayout = "e-p:64:64-i64:64-n8:16:32"
13+
target triple = "spir64-unknown-unknown"
14+
15+
%user.type = type { [1 x i32] }
16+
17+
; CHECK: ModuleInfo:
18+
; CHECK: Constant
19+
; CHECK: Data:
20+
; CHECK: Buffer: [
21+
@GV = internal addrspace(1) constant [2 x %user.type] [%user.type zeroinitializer, %user.type { [1 x i32] [i32 2139095040] }], align 4
22+
; CHECK-SAME: 0, 0, 0, 0, 0, 0, 128, 127,
23+
; CHECK: ]
24+
; CHECK: Symbols:
25+
; CHECK-NEXT: - s_type: S_GLOBAL_VAR_CONST
26+
; CHECK-NEXT: s_offset: 0
27+
; CHECK-NEXT: s_size: 8
28+
; CHECK-NEXT: s_name: GV
29+
30+
@reloc = internal addrspace(1) constant i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ([2 x %user.type] addrspace(1)* @GV to i8 addrspace(1)*) to i8 addrspace(4)*), align 8
31+
@llvm.compiler.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* bitcast (i8 addrspace(4)* addrspace(1)* @reloc to i8 addrspace(1)*) to i8*)]
32+
33+
; Function Attrs: noinline nounwind
34+
define dllexport spir_kernel void @test_kernel(i64 %privBase) local_unnamed_addr #0 {
35+
ret void
36+
}
37+
38+
attributes #0 = { noinline nounwind "CMGenxMain" "VCFunction" "VCNamedBarrierCount"="0" "VCSLMSize"="0" }
39+
40+
!llvm.module.flags = !{!0, !1}
41+
!llvm.dbg.cu = !{!2}
42+
!opencl.enable.FP_CONTRACT = !{}
43+
!genx.kernels = !{!6}
44+
!genx.kernel.internal = !{!10}
45+
46+
!0 = !{i32 2, !"Dwarf Version", i32 4}
47+
!1 = !{i32 2, !"Debug Info Version", i32 3}
48+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "spirv", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
49+
!3 = !DIFile(filename: "kernel_genx.cpp", directory: "/the_directory/")
50+
!4 = !{}
51+
!5 = !{}
52+
!6 = !{void (i64)* @test_kernel, !"test_kernel", !7, i32 0, !8, !5, !9, i32 0}
53+
!7 = !{i32 96}
54+
!8 = !{i32 0}
55+
!9 = !{}
56+
!10 = !{void (i64)* @test_kernel, !11, !11, null, !11}
57+
!11 = !{i32 0}

0 commit comments

Comments
 (0)