1; Test traps and conditional traps
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4
5declare void @llvm.trap()
6
7; Check unconditional traps
8define i32 @f0() {
9; CHECK-LABEL: f0:
10; CHECK-LABEL: .Ltmp0
11; CHECK: j .Ltmp0+2
12entry:
13  tail call void @llvm.trap()
14  ret i32 0
15}
16
17; Check conditional compare immediate and trap
18define i32 @f1(i32 signext %a) {
19; CHECK-LABEL: f1:
20; CHECK: cithe %r2, 15
21; CHECK: lhi %r2, 0
22; CHECK: br %r14
23entry:
24  %cmp = icmp sgt i32 %a, 14
25  br i1 %cmp, label %if.then, label %if.end
26
27if.then:                                          ; preds = %entry
28  tail call void @llvm.trap()
29  unreachable
30
31if.end:                                           ; preds = %entry
32  ret i32 0
33}
34
35; Check conditional compare grande immediate and trap
36define i64 @f2(i64 signext %a) {
37; CHECK-LABEL: f2:
38; CHECK: cgitle %r2, 14
39; CHECK: lghi %r2, 0
40; CHECK: br %r14
41entry:
42  %cmp = icmp slt i64 %a, 15
43  br i1 %cmp, label %if.then, label %if.end
44
45if.then:                                          ; preds = %entry
46  tail call void @llvm.trap()
47  unreachable
48
49if.end:                                           ; preds = %entry
50  ret i64 0
51}
52
53; Check conditional compare logical immediate and trap
54define i32 @f3(i32 zeroext %a) {
55; CHECK-LABEL: f3:
56; CHECK: clfithe %r2, 15
57; CHECK: lhi %r2, 0
58; CHECK: br %r14
59entry:
60  %cmp = icmp ugt i32 %a, 14
61  br i1 %cmp, label %if.then, label %if.end
62
63if.then:                                          ; preds = %entry
64  tail call void @llvm.trap()
65  unreachable
66
67if.end:                                           ; preds = %entry
68  ret i32 0
69}
70
71; Check conditional compare grande logical immediate and trap
72define i64 @f4(i64 zeroext %a) {
73; CHECK-LABEL: f4:
74; CHECK: clgitle %r2, 14
75; CHECK: lghi %r2, 0
76; CHECK: br %r14
77entry:
78  %cmp = icmp ult i64 %a, 15
79  br i1 %cmp, label %if.then, label %if.end
80
81if.then:                                          ; preds = %entry
82  tail call void @llvm.trap()
83  unreachable
84
85if.end:                                           ; preds = %entry
86  ret i64 0
87}
88
89; Check conditional compare and trap
90define i32 @f5(i32 signext %a, i32 signext %b) {
91; CHECK-LABEL: f5:
92; CHECK: crte %r2, %r3
93; CHECK: lhi %r2, 0
94; CHECK: br %r14
95entry:
96  %cmp = icmp eq i32 %a, %b
97  br i1 %cmp, label %if.then, label %if.end
98
99if.then:                                          ; preds = %entry
100  tail call void @llvm.trap()
101  unreachable
102
103if.end:                                           ; preds = %entry
104  ret i32 0
105}
106
107; Check conditional compare grande and trap
108define i64 @f6(i64 signext %a, i64 signext %b) {
109; CHECK-LABEL: f6:
110; CHECK: cgrtl %r2, %r3
111; CHECK: lghi %r2, 0
112; CHECK: br %r14
113entry:
114  %cmp = icmp slt i64 %a, %b
115  br i1 %cmp, label %if.then, label %if.end
116
117if.then:                                          ; preds = %entry
118  tail call void @llvm.trap()
119  unreachable
120
121if.end:                                           ; preds = %entry
122  ret i64 0
123}
124
125; Check conditional compare logical and trap
126define i32 @f7(i32 zeroext %a, i32 zeroext %b) {
127; CHECK-LABEL: f7:
128; CHECK: clrth %r2, %r3
129; CHECK: lhi %r2, 0
130; CHECK: br %r14
131entry:
132  %cmp = icmp ugt i32 %a, %b
133  br i1 %cmp, label %if.then, label %if.end
134
135if.then:                                          ; preds = %entry
136  tail call void @llvm.trap()
137  unreachable
138
139if.end:                                           ; preds = %entry
140  ret i32 0
141}
142
143; Check conditional compare logical grande and trap
144define i64 @f8(i64 zeroext %a, i64 zeroext %b) {
145; CHECK-LABEL: f8:
146; CHECK: clgrtl %r2, %r3
147; CHECK: lghi %r2, 0
148; CHECK: br %r14
149entry:
150  %cmp = icmp ult i64 %a, %b
151  br i1 %cmp, label %if.then, label %if.end
152
153if.then:                                          ; preds = %entry
154  tail call void @llvm.trap()
155  unreachable
156
157if.end:                                           ; preds = %entry
158  ret i64 0
159}
160
161; Check conditional traps that don't have a valid Compare and Trap
162define double @f9(double %a, double %b) {
163; CHECK-LABEL: f9:
164; CHECK: cdbr %f0, %f2
165; CHECK-LABEL: .Ltmp1
166; CHECK: je .Ltmp1+2
167; CHECK: lzdr %f0
168; CHECK: br %r14
169entry:
170  %cmp = fcmp oeq double %a, %b
171  br i1 %cmp, label %if.then, label %if.end
172
173if.then:                                          ; preds = %entry
174  tail call void @llvm.trap()
175  unreachable
176
177if.end:                                           ; preds = %entry
178  ret double 0.000000e+00
179}
180