File: fix-struct-ret-args-indirect-call-opaque-pointers.ll

package info (click to toggle)
intel-graphics-compiler2 2.28.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 792,744 kB
  • sloc: cpp: 5,761,745; ansic: 466,928; lisp: 312,143; python: 114,790; asm: 44,736; pascal: 10,930; sh: 8,033; perl: 7,914; ml: 3,625; awk: 3,523; yacc: 2,747; javascript: 2,667; lex: 1,898; f90: 1,028; cs: 573; xml: 474; makefile: 344; objc: 162
file content (106 lines) | stat: -rw-r--r-- 4,061 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
;=========================== begin_copyright_notice ============================
;
; Copyright (C) 2025 Intel Corporation
;
; SPDX-License-Identifier: MIT
;
;============================ end_copyright_notice =============================
;
; REQUIRES: llvm-15-plus
; RUN: igc_opt --opaque-pointers --igc-legalize-function-signatures -S < %s 2>&1 | FileCheck %s
; ------------------------------------------------
; LegalizeFunctionSignatures
; ------------------------------------------------

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

%struct._st_foo = type { i32, i32 }

define spir_kernel void @foo(i1 %condition) #1 {
; CHECK:      define spir_kernel void @foo(i8 %condition)
; CHECK: [[CONDITION:%.*]] = trunc i8 %condition to i1
    %a = alloca %struct._st_foo
; CHECK-NEXT:     [[A:%.*]] = alloca %struct._st_foo, align 8
    %func_addr = select i1 %condition, ptr @bar_0, ptr @bar_1
; CHECK-NEXT: [[FUNC_ADDR:%.*]] = select i1 [[CONDITION]], ptr @bar_0, ptr @bar_1
    call void %func_addr(ptr sret(%struct._st_foo) %a)
; CHECK-NEXT:     [[RET_BAR_0:%.*]] = call %struct._st_foo [[FUNC_ADDR]]()
; 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
    store %struct._st_foo { i32 10, i32 20 }, ptr %out, align 4
; CHECK-NEXT:   store %struct._st_foo { i32 10, i32 20 }, 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: }

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)