Skip to content

Commit bea8acd

Browse files
aratajewigcbot
authored andcommitted
Fix bindless loads merging in ConstantCoalescing
If there is any user function call between candidates to merge, we must treat such call as if it was aliased write, because we never know whether callee may change the same memory or not.
1 parent 86cf530 commit bea8acd

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

IGC/Compiler/CISACodeGen/ConstantCoalescing.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,13 @@ bool ConstantCoalescing::CheckForAliasingWrites(
25662566
{
25672567
return true;
25682568
}
2569+
// Treat all calls to user functions that can write to memory as if they
2570+
// could change results of subsequent loads.
2571+
if (isUserFunctionCall(inst) && inst->mayWriteToMemory())
2572+
{
2573+
return true;
2574+
}
2575+
25692576
if (!inst->mayWriteToMemory())
25702577
{
25712578
return false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; REQUIRES: llvm-14-plus
10+
; RUN: igc_opt --opaque-pointers %s -S -o - -igc-constant-coalescing | FileCheck %s
11+
12+
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f80:128:128-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-a:64:64-f80:128:128-n8:16:32:64"
13+
14+
define <2 x float> @test_regular_function_call(ptr addrspace(1) %arg0, i32 %bindlessOffset_arg0) {
15+
entry:
16+
%0 = inttoptr i32 %bindlessOffset_arg0 to ptr addrspace(2490373)
17+
%1 = call fast float @llvm.genx.GenISA.ldraw.indexed.f32.p2490373(ptr addrspace(2490373) %0, i32 0, i32 4, i1 false)
18+
call void @callee(ptr addrspace(1) %arg0)
19+
%2 = call fast float @llvm.genx.GenISA.ldraw.indexed.f32.p2490373(ptr addrspace(2490373) %0, i32 4, i32 4, i1 false)
20+
%3 = insertelement <2 x float> undef, float %1, i32 0
21+
%4 = insertelement <2 x float> %3, float %2, i32 1
22+
ret <2 x float> %4
23+
}
24+
25+
define void @callee(ptr addrspace(1) %ptr) {
26+
entry:
27+
store i32 1, ptr addrspace(1) %ptr
28+
ret void
29+
}
30+
31+
; CHECK-LABEL: define <2 x float> @test_regular_function_call
32+
; CHECK-NOT: call <2 x float> @llvm.genx.GenISA.ldrawvector.indexed.v2f32.p2490373
33+
34+
define <2 x float> @test_indirect_function_call(ptr %fptr, ptr addrspace(1) %arg0, i32 %bindlessOffset_arg0) {
35+
entry:
36+
%0 = inttoptr i32 %bindlessOffset_arg0 to ptr addrspace(2490373)
37+
%1 = call fast float @llvm.genx.GenISA.ldraw.indexed.f32.p2490373(ptr addrspace(2490373) %0, i32 0, i32 4, i1 false)
38+
call void %fptr(ptr addrspace(1) %arg0)
39+
%2 = call fast float @llvm.genx.GenISA.ldraw.indexed.f32.p2490373(ptr addrspace(2490373) %0, i32 4, i32 4, i1 false)
40+
%3 = insertelement <2 x float> undef, float %1, i32 0
41+
%4 = insertelement <2 x float> %3, float %2, i32 1
42+
ret <2 x float> %4
43+
}
44+
45+
; CHECK-LABEL: define <2 x float> @test_indirect_function_call
46+
; CHECK-NOT: call <2 x float> @llvm.genx.GenISA.ldrawvector.indexed.v2f32.p2490373
47+
48+
; Function Attrs: argmemonly nounwind readonly
49+
declare float @llvm.genx.GenISA.ldraw.indexed.f32.p2490373(ptr addrspace(2490373), i32, i32, i1) argmemonly nounwind readonly
50+
51+
; Function Attrs: argmemonly nounwind writeonly
52+
declare void @llvm.genx.GenISA.storeraw.indexed.p2490368.f32(ptr addrspace(2490373), i32, float, i32, i1) argmemonly nounwind writeonly
53+
54+
55+
!igc.functions = !{!0, !3, !4}
56+
57+
!0 = !{ptr @test_regular_function_call, !1}
58+
!3 = !{ptr @callee, !1}
59+
!4 = !{ptr @test_indirect_function_call, !1}
60+
61+
!1 = !{!2}
62+
!2 = !{!"function_type", i32 0}

0 commit comments

Comments
 (0)