forked from KhronosGroup/SPIRV-LLVM-Translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
freeze.ll
111 lines (98 loc) · 3.69 KB
/
freeze.ll
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
111
;; Test to check that freeze instruction does not cause a crash
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; All freeze instructions should be deleted and uses of freeze's result should be replaced
; with freeze's source or a random constant if freeze's source is poison or undef.
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM --implicit-check-not="= freeze"
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
target triple = "spir64-unknown-unknown"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; test i32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CHECK-LLVM: @testfunction_i32A
; Uses of result should be replaced with freeze's source
; CHECK-LLVM-NEXT: add nsw i32 %val, 1
define spir_func i32 @testfunction_i32A(i32 %val) {
%1 = freeze i32 %val
%2 = add nsw i32 %1, 1
ret i32 %2
}
; CHECK-LLVM: @testfunction_i32B
; Frozen poison/undef should produce a constant.
; add should be deleted since both inputs are constant.
; CHECK-LLVM-NEXT: ret i32
define spir_func i32 @testfunction_i32B(i32 %val) {
%1 = freeze i32 poison
%2 = add nsw i32 %1, 1
ret i32 %2
}
; CHECK-LLVM: @testfunction_i32C
; Frozen poison/undef should produce a constant.
; add should be deleted since both inputs are constant.
; CHECK-LLVM-NEXT: ret i32
define spir_func i32 @testfunction_i32C(i32 %val) {
%1 = freeze i32 undef
%2 = add nsw i32 %1, 1
ret i32 %2
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; test float
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CHECK-LLVM: @testfunction_floatA
; freeze should be eliminated.
; Uses of result should be replaced with freeze's source
; CHECK-LLVM-NEXT: fadd float %val
define spir_func float @testfunction_floatA(float %val) {
%1 = freeze float %val
%2 = fadd float %1, 1.0
ret float %2
}
; CHECK-LLVM: @testfunction_floatB
; Frozen poison/undef should produce a constant.
; add should be deleted since both inputs are constant.
; CHECK-LLVM-NEXT: ret float
define spir_func float @testfunction_floatB(float %val) {
%1 = freeze float poison
%2 = fadd float %1, 1.0
ret float %2
}
; CHECK-LLVM: @testfunction_floatC
; Frozen poison/undef should produce a constant.
; add should be deleted since both inputs are constant.
; CHECK-LLVM-NEXT: ret float
define spir_func float @testfunction_floatC(float %val) {
%1 = freeze float undef
%2 = fadd float %1, 1.0
ret float %2
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; test ptr
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CHECK-LLVM: @testfunction_ptrA
; freeze should be eliminated.
; Uses of result should be replaced with freeze's source
; CHECK-LLVM-NEXT: ptrtoint ptr %val to i64
define spir_func i64 @testfunction_ptrA(ptr %val) {
%1 = freeze ptr %val
%2 = ptrtoint ptr %1 to i64
ret i64 %2
}
; CHECK-LLVM: @testfunction_ptrB
; Frozen poison/undef should produce a constant.
; For ptr type this constant is null.
; CHECK-LLVM-NEXT: ptrtoint ptr null to i64
define spir_func i64 @testfunction_ptrB(ptr addrspace(1) %val) {
%1 = freeze ptr poison
%2 = ptrtoint ptr %1 to i64
ret i64 %2
}
; CHECK-LLVM: @testfunction_ptrC
; Frozen poison/undef should produce a constant.
; For ptr type this constant is null.
; CHECK-LLVM-NEXT: ptrtoint ptr null to i64
define spir_func i64 @testfunction_ptrC(ptr addrspace(1) %val) {
%1 = freeze ptr undef
%2 = ptrtoint ptr %1 to i64
ret i64 %2
}