File: fix-struct-ret-args.ll

package info (click to toggle)
intel-graphics-compiler2 2.22.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 107,676 kB
  • sloc: cpp: 809,645; lisp: 288,070; ansic: 16,397; python: 4,010; yacc: 2,588; lex: 1,666; pascal: 314; sh: 186; makefile: 38
file content (110 lines) | stat: -rw-r--r-- 4,208 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
;=========================== begin_copyright_notice ============================
;
; Copyright (C) 2024 Intel Corporation
;
; SPDX-License-Identifier: MIT
;
;============================ end_copyright_notice =============================
;
; RUN: igc_opt --opaque-pointers --igc-legalize-function-signatures -S < %s 2>&1 | FileCheck %s
; ------------------------------------------------
; LegalizeFunctionSignatures
; ------------------------------------------------

; Pseudo-code:
; Before:
;   void foo()
;   {
;     st_foo a;
;     bar_0(&a)
;     consume(&a);
;   }
;
;   void bar_0(st_foo* out)
;   {
;     bar_1(out);
;   }
;
;   void bar_1(st_foo* out)
;   {
;     *out = {1, 2};
;   }
; After:
;   void foo()
;   {
;     st_foo a;
;     a = bar_0();
;     consume(&a);
;   }
;
;   st_foo bar_0()
;   {
;     return bar_1();
;   }
;
;   st_foo bar_1(st_foo* in)
;   {
;     st_foo out = {1, 2};
;     return out;
;   }

%struct._st_foo = type { i32, i32 }

define spir_kernel void @foo() #1 {
; CHECK:      define spir_kernel void @foo()
    %a = alloca %struct._st_foo
; CHECK-NEXT:     [[A:%.*]] = alloca %struct._st_foo, align 8
    call void @bar_0(ptr sret(%struct._st_foo) %a)
; CHECK-NEXT:     [[RET_BAR_0:%.*]] = call %struct._st_foo @bar_0()
; CHECK-NEXT:     [[M_0_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[A]], i32 0, i32 0
; CHECK-NEXT:     [[M_0:%.*]] = extractvalue %struct._st_foo [[RET_BAR_0]], 0
; CHECK-NEXT:     store i32 [[M_0]], ptr [[M_0_PTR]], align 4
; CHECK-NEXT:     [[M_1_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[A]], i32 0, i32 1
; CHECK-NEXT:     [[M_1:%.*]] = extractvalue %struct._st_foo [[RET_BAR_0]], 1
; CHECK-NEXT:     store i32 [[M_1]], ptr [[M_1_PTR]], align 4
    call void @consume(ptr %a)
; CHECK-NEXT:     call void @consume(ptr [[A]])
    ret void
; CHECK-NEXT:     ret void
}
; CHECK-NEXT: }

define linkonce_odr spir_func void @bar_0(ptr sret(%struct._st_foo) %out) {
; CHECK:      define linkonce_odr spir_func %struct._st_foo @bar_0()
; CHECK-NEXT:   [[OUT:%.*]] = alloca %struct._st_foo, align 8
    call void @bar_1(ptr sret(%struct._st_foo) %out)
; CHECK-NEXT:     [[RET_BAR_1:%.*]] = call %struct._st_foo @bar_1()
; CHECK-NEXT:     [[M_0_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 0
; CHECK-NEXT:     [[M_0:%.*]] = extractvalue %struct._st_foo [[RET_BAR_1]], 0
; CHECK-NEXT:     store i32 [[M_0]], ptr [[M_0_PTR]], align 4
; CHECK-NEXT:     [[M_1_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 1
; CHECK-NEXT:     [[M_1:%.*]] = extractvalue %struct._st_foo [[RET_BAR_1]], 1
; CHECK-NEXT:     store i32 [[M_1]], ptr [[M_1_PTR]], align 4
    ret void
; CHECK-NEXT:   [[M_0_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 0
; CHECK-NEXT:   [[M_0:%.*]] = load i32, ptr [[M_0_PTR]], align 4
; CHECK-NEXT:   [[R_0:%.*]] = insertvalue %struct._st_foo undef, i32 [[M_0]], 0
; CHECK-NEXT:   [[M_1_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 1
; CHECK-NEXT:   [[M_1:%.*]] = load i32, ptr [[M_1_PTR]], align 4
; CHECK-NEXT:   [[R_1:%.*]] = insertvalue %struct._st_foo [[R_0]], i32 [[M_1]], 1
; CHECK-NEXT:   ret %struct._st_foo [[R_1]]
}
; CHECK-NEXT: }

define linkonce_odr spir_func void @bar_1(ptr sret(%struct._st_foo) %out) {
; CHECK:      define linkonce_odr spir_func %struct._st_foo @bar_1()
; CHECK-NEXT:   [[OUT:%.*]] = alloca %struct._st_foo, align 8
    store %struct._st_foo { i32 1, i32 2 }, ptr %out, align 4
; CHECK-NEXT:   store %struct._st_foo { i32 1, i32 2 }, ptr [[OUT]], align 4
    ret void
; CHECK-NEXT:   [[M_0_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 0
; CHECK-NEXT:   [[M_0:%.*]] = load i32, ptr [[M_0_PTR]], align 4
; CHECK-NEXT:   [[R_0:%.*]] = insertvalue %struct._st_foo undef, i32 [[M_0]], 0
; CHECK-NEXT:   [[M_1_PTR:%.*]] = getelementptr inbounds %struct._st_foo, ptr [[OUT]], i32 0, i32 1
; CHECK-NEXT:   [[M_1:%.*]] = load i32, ptr [[M_1_PTR]], align 4
; CHECK-NEXT:   [[R_1:%.*]] = insertvalue %struct._st_foo [[R_0]], i32 [[M_1]], 1
; CHECK-NEXT:   ret %struct._st_foo [[R_1]]
}
; CHECK-NEXT: }

declare spir_func void @consume(ptr)