Skip to content

Commit e2c4ba8

Browse files
ViacheslavRbigcbot
authored andcommitted
Bitcast in StatelessToStateful pass
The fix prevents crash in StatelessToStateful pass if all ptr usees are bitcast instructions.
1 parent a057740 commit e2c4ba8

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

IGC/Compiler/Optimizer/OpenCLPasses/StatelessToStateful/StatelessToStateful.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ bool StatelessToStateful::pointerIsFromKernelArgument(Value &ptr) {
522522

523523
static alignment_t determinePointerAlignment(Value *Ptr, const DataLayout &DL, AssumptionCache *AC,
524524
Instruction *InsertionPt) {
525-
alignment_t BestAlign = 0;
525+
alignment_t BestAlign = 1;
526526

527527
// 1) Examine uses: look for loads/stores (which may carry explicit
528528
// alignment) or a GEP that reveals an ABI alignment from its element
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: igc_opt --typed-pointers %s -S -o - -igc-stateless-to-stateful-resolution -igc-serialize-metadata -platformpvc | FileCheck %s
10+
11+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
12+
13+
define spir_kernel void @test(i64 addrspace(1)* %dst, i32 %bufferOffset) {
14+
entry:
15+
; CHECK: %[[OFFSET:[0-9]+]] = add i32 %bufferOffset, 1
16+
; CHECK: %[[PTR:[0-9]+]] = inttoptr i32 %[[OFFSET]] to i8 addrspace(131072)*
17+
; CHECK: store i8 0, i8 addrspace(131072)* %[[PTR]], align 1
18+
%bc = bitcast i64 addrspace(1)* %dst to i8 addrspace(1)*
19+
%ptr = getelementptr inbounds i8, i8 addrspace(1)* %bc, i64 1
20+
store i8 0, i8 addrspace(1)* %ptr, align 1
21+
ret void
22+
}
23+
24+
!IGCMetadata = !{!0}
25+
!igc.functions = !{!1}
26+
27+
!0 = !{!"ModuleMD", !5, !16}
28+
!1 = !{void (i64 addrspace(1)*, i32)* @test, !2}
29+
!2 = !{!3, !14}
30+
!3 = !{!"function_type", i32 0}
31+
!4 = !{}
32+
!5 = !{!"FuncMD", !6, !7}
33+
!6 = !{!"FuncMDMap[0]", void (i64 addrspace(1)*, i32)* @test}
34+
!7 = !{!"FuncMDValue[0]", !8}
35+
!8 = !{!"resAllocMD", !9}
36+
!9 = !{!"argAllocMDList", !10}
37+
!10 = !{!"argAllocMDListVec[0]", !11}
38+
!11 = !{!"type", i32 1}
39+
!12 = !{!"extensionType", i32 -1}
40+
!13 = !{!"indexType", i32 0}
41+
!14 = !{!"implicit_arg_desc", !15}
42+
!15 = !{i32 15}
43+
!16 = !{!"compOpt", !17}
44+
!17 = !{!"HasBufferOffsetArg", i1 true}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: igc_opt --opaque-pointers %s -S -o - -igc-stateless-to-stateful-resolution -igc-serialize-metadata -platformpvc | FileCheck %s
10+
11+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
12+
13+
define spir_kernel void @test(ptr addrspace(1) %dst, i32 %bufferOffset) {
14+
entry:
15+
; CHECK: %[[OFFSET:[0-9]+]] = add i32 %bufferOffset, 1
16+
; CHECK: %[[PTR:[0-9]+]] = inttoptr i32 %[[OFFSET]] to ptr addrspace(131072)
17+
; CHECK: store i8 0, ptr addrspace(131072) %[[PTR]], align 1
18+
%bc = bitcast ptr addrspace(1) %dst to ptr addrspace(1)
19+
%ptr = getelementptr inbounds i8, ptr addrspace(1) %bc, i64 1
20+
store i8 0, ptr addrspace(1) %ptr, align 1
21+
ret void
22+
}
23+
24+
!IGCMetadata = !{!0}
25+
!igc.functions = !{!10}
26+
27+
!0 = !{!"ModuleMD", !1, !8}
28+
!1 = !{!"FuncMD", !2, !3}
29+
!2 = !{!"FuncMDMap[0]", ptr @test}
30+
!3 = !{!"FuncMDValue[0]", !4}
31+
!4 = !{!"resAllocMD", !5}
32+
!5 = !{!"argAllocMDList", !6}
33+
!6 = !{!"argAllocMDListVec[0]", !7}
34+
!7 = !{!"type", i32 1}
35+
!8 = !{!"compOpt", !9}
36+
!9 = !{!"HasBufferOffsetArg", i1 true}
37+
!10 = !{ptr @test, !11}
38+
!11 = !{!12, !13}
39+
!12 = !{!"function_type", i32 0}
40+
!13 = !{!"implicit_arg_desc", !14}
41+
!14 = !{i32 15}

0 commit comments

Comments
 (0)