Skip to content

Commit 0bf0367

Browse files
bokrzesiigcbot
authored andcommitted
Reverting recent changes related to sret argument in LegalizeFunctionSignatures pass
Reverting changes introduced here: 7a45c84 Due to performance regression
1 parent 62bd483 commit 0bf0367

File tree

2 files changed

+55
-22
lines changed

2 files changed

+55
-22
lines changed

IGC/AdaptorCommon/LegalizeFunctionSignatures.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,6 @@ void LegalizeFunctionSignatures::FixFunctionSignatures(Module& M)
294294
// Create the new function signature by replacing the illegal types
295295
if (FunctionHasPromotableSRetArg(M, pFunc))
296296
{
297-
// According to docs: https://llvm.org/docs/LangRef.html
298-
// "A function that accepts an sret argument must return void. A return value may not be sret."
299-
// So I'm skipping further modifications of such functions
300-
// Because e.g
301-
// spir_func void @__devicelib_catanf(%structtype addrspace(4)* sret(%structtype) align 4, (...)
302-
// Was changed into
303-
// declare spir_func %structtype @__devicelib_catanf(%structtype sret(%structtype) align 4)
304-
// Which resulted in:
305-
// Invalid struct return type!
306-
// % structtype(% structtype)* @__devicelib_catanf
307-
continue;
308-
309297
retTypeOption = ReturnOpt::RETURN_STRUCT;
310298
ai++; // Skip adding the first arg
311299
}

IGC/Compiler/tests/LegalizeFunctionSignatures/fix-struct-ret-args.ll

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
; ------------------------------------------------
1313

1414
; Pseudo-code:
15+
; Before:
1516
; void foo()
1617
; {
1718
; st_foo a;
@@ -28,37 +29,81 @@
2829
; {
2930
; *out = {1, 2};
3031
; }
32+
; After:
33+
; void foo()
34+
; {
35+
; st_foo a;
36+
; a = bar_0();
37+
; consume(&a);
38+
; }
39+
;
40+
; st_foo bar_0()
41+
; {
42+
; return bar_1();
43+
; }
44+
;
45+
; st_foo bar_1(st_foo* in)
46+
; {
47+
; st_foo out = {1, 2};
48+
; return out;
49+
; }
3150

3251
%struct._st_foo = type { i32, i32 }
3352

3453
define spir_kernel void @foo() #1 {
3554
; CHECK: define spir_kernel void @foo()
36-
; CHECK-NEXT: [[A:%.*]] = alloca %struct._st_foo, align 8
37-
; CHECK-NEXT: call void @bar_0(ptr sret(%struct._st_foo) [[A]])
38-
; CHECK-NEXT: call void @consume(ptr [[A]])
39-
; CHECK-NEXT: ret void
4055
%a = alloca %struct._st_foo
56+
; CHECK-NEXT: [[A:%.*]] = alloca %struct._st_foo, align 8
4157
call void @bar_0(ptr sret(%struct._st_foo) %a)
58+
; CHECK-NEXT: [[RET_BAR_0:%.*]] = call %struct._st_foo @bar_0()
59+
; CHECK-NEXT: [[M_0_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[A]], i32 0, i32 0
60+
; CHECK-NEXT: [[M_0:%.*]] = extractvalue %struct._st_foo [[RET_BAR_0]], 0
61+
; CHECK-NEXT: store i32 [[M_0]], ptr [[M_0_PTR]], align 4
62+
; CHECK-NEXT: [[M_1_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[A]], i32 0, i32 1
63+
; CHECK-NEXT: [[M_1:%.*]] = extractvalue %struct._st_foo [[RET_BAR_0]], 1
64+
; CHECK-NEXT: store i32 [[M_1]], ptr [[M_1_PTR]], align 4
4265
call void @consume(ptr %a)
66+
; CHECK-NEXT: call void @consume(ptr [[A]])
4367
ret void
68+
; CHECK-NEXT: ret void
4469
}
4570
; CHECK-NEXT: }
4671

4772
define linkonce_odr spir_func void @bar_0(ptr sret(%struct._st_foo) %out) {
48-
; CHECK: define linkonce_odr spir_func void @bar_0(ptr sret(%struct._st_foo) %out) {
49-
; CHECK-NEXT: call void @bar_1(ptr sret(%struct._st_foo) %out)
50-
; CHECK-NEXT: ret void
73+
; CHECK: define linkonce_odr spir_func %struct._st_foo @bar_0()
74+
; CHECK-NEXT: [[OUT:%.*]] = alloca %struct._st_foo, align 8
5175
call void @bar_1(ptr sret(%struct._st_foo) %out)
76+
; CHECK-NEXT: [[RET_BAR_1:%.*]] = call %struct._st_foo @bar_1()
77+
; CHECK-NEXT: [[M_0_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 0
78+
; CHECK-NEXT: [[M_0:%.*]] = extractvalue %struct._st_foo [[RET_BAR_1]], 0
79+
; CHECK-NEXT: store i32 [[M_0]], ptr [[M_0_PTR]], align 4
80+
; CHECK-NEXT: [[M_1_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 1
81+
; CHECK-NEXT: [[M_1:%.*]] = extractvalue %struct._st_foo [[RET_BAR_1]], 1
82+
; CHECK-NEXT: store i32 [[M_1]], ptr [[M_1_PTR]], align 4
5283
ret void
84+
; CHECK-NEXT: [[M_0_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 0
85+
; CHECK-NEXT: [[M_0:%.*]] = load i32, ptr [[M_0_PTR]], align 4
86+
; CHECK-NEXT: [[R_0:%.*]] = insertvalue %struct._st_foo undef, i32 [[M_0]], 0
87+
; CHECK-NEXT: [[M_1_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 1
88+
; CHECK-NEXT: [[M_1:%.*]] = load i32, ptr [[M_1_PTR]], align 4
89+
; CHECK-NEXT: [[R_1:%.*]] = insertvalue %struct._st_foo [[R_0]], i32 [[M_1]], 1
90+
; CHECK-NEXT: ret %struct._st_foo [[R_1]]
5391
}
5492
; CHECK-NEXT: }
5593

5694
define linkonce_odr spir_func void @bar_1(ptr sret(%struct._st_foo) %out) {
57-
; CHECK: define linkonce_odr spir_func void @bar_1(ptr sret(%struct._st_foo) %out) {
58-
; CHECK-NEXT: store %struct._st_foo { i32 1, i32 2 }, ptr %out, align 4
59-
; CHECK-NEXT: ret void
95+
; CHECK: define linkonce_odr spir_func %struct._st_foo @bar_1()
96+
; CHECK-NEXT: [[OUT:%.*]] = alloca %struct._st_foo, align 8
6097
store %struct._st_foo { i32 1, i32 2 }, ptr %out, align 4
98+
; CHECK-NEXT: store %struct._st_foo { i32 1, i32 2 }, ptr [[OUT]], align 4
6199
ret void
100+
; CHECK-NEXT: [[M_0_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 0
101+
; CHECK-NEXT: [[M_0:%.*]] = load i32, ptr [[M_0_PTR]], align 4
102+
; CHECK-NEXT: [[R_0:%.*]] = insertvalue %struct._st_foo undef, i32 [[M_0]], 0
103+
; CHECK-NEXT: [[M_1_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 1
104+
; CHECK-NEXT: [[M_1:%.*]] = load i32, ptr [[M_1_PTR]], align 4
105+
; CHECK-NEXT: [[R_1:%.*]] = insertvalue %struct._st_foo [[R_0]], i32 [[M_1]], 1
106+
; CHECK-NEXT: ret %struct._st_foo [[R_1]]
62107
}
63108
; CHECK-NEXT: }
64109

0 commit comments

Comments
 (0)