Skip to content

Commit 6b2bd17

Browse files
varev-devigcbot
authored andcommitted
Handle addrspacecast of Null in ConstantEncoder
This change adds a safe handling path for addrspacecast of a Null pointer in ConstantEncoder. Previously, such case triggered a diagnostic error even though the semantic value is equivalent to a plain Null in the destination address space.
1 parent f788498 commit 6b2bd17

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/ConstantEncoder.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ encodeConstExprImpl(const IGCLLVM::AddrSpaceCastOperator &ASC,
7676
const DataLayout &DL) {
7777
IGC_ASSERT_MESSAGE(!isa<IGCLLVM::FixedVectorType>(ASC.getType()),
7878
"vector addrspacecast is not yet supported");
79-
auto [Data, Relocs] = vc::encodeGlobalValueOrConstantExpression(
80-
*cast<Constant>(ASC.getPointerOperand()), DL);
79+
auto *OpC = cast<Constant>(ASC.getPointerOperand());
80+
81+
if (OpC->isNullValue()) {
82+
const auto DstBits = vc::getTypeSize(ASC.getType(), &DL).inBits();
83+
return {APInt(DstBits, 0), {}};
84+
}
85+
86+
auto [Data, Relocs] = vc::encodeGlobalValueOrConstantExpression(*OpC, DL);
8187

8288
// FIXME: p3 to p4 cast should also be part of this case if we consider
8389
// p3 higher bits are marked from the beginning. Alternatively those
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2021-2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
10+
; RUN: %llc_opaque_ptrs %s -march=genx64 -mcpu=Gen9 -mattr=+ocl_runtime -vc-analyze=GenXOCLRuntimeInfo \
11+
; RUN: -vc-choose-pass-manager-override=false -o /dev/null 2>&1 | FileCheck %s --check-prefixes=CHECK
12+
13+
target datalayout = "e-p:64:64-i64:64-n8:16:32"
14+
target triple = "spir64-unknown-unknown"
15+
16+
; CHECK: Printing analysis 'GenXOCLRuntimeInfo':
17+
18+
; CHECK: Global:
19+
; CHECK: Data:
20+
; CHECK: Buffer: [
21+
@global.casted_null = addrspace(1) global ptr addrspace(1) addrspacecast (ptr addrspace(4) null to ptr addrspace(1)), align 8
22+
; CHECK-COUNT-7: 0,
23+
; CHECK-SAME: 0 ]
24+
; CHECK: Symbols:
25+
; CHECK-NEXT: - s_type: S_GLOBAL_VAR
26+
; CHECK-NEXT: s_offset: 0
27+
; CHECK-NEXT: s_size: 8
28+
; CHECK-NEXT: s_name: global.casted_null

0 commit comments

Comments
 (0)