1; Test zE12 conditional traps
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=zEC12 | FileCheck %s
4
5declare void @llvm.trap()
6
7; Check conditional compare logical and trap
8define i32 @f1(i32 zeroext %a, i32 *%ptr) {
9; CHECK-LABEL: f1:
10; CHECK: clth %r2, 0(%r3)
11; CHECK: lhi %r2, 0
12; CHECK: br %r14
13entry:
14  %b = load i32, i32 *%ptr
15  %cmp = icmp ugt i32 %a, %b
16  br i1 %cmp, label %if.then, label %if.end
17
18if.then:                                          ; preds = %entry
19  tail call void @llvm.trap()
20  unreachable
21
22if.end:                                           ; preds = %entry
23  ret i32 0
24}
25
26; Check conditional compare logical grande and trap
27define i64 @f2(i64 zeroext %a, i64 *%ptr) {
28; CHECK-LABEL: f2:
29; CHECK: clgtl %r2, 0(%r3)
30; CHECK: lghi %r2, 0
31; CHECK: br %r14
32entry:
33  %b = load i64, i64 *%ptr
34  %cmp = icmp ult i64 %a, %b
35  br i1 %cmp, label %if.then, label %if.end
36
37if.then:                                          ; preds = %entry
38  tail call void @llvm.trap()
39  unreachable
40
41if.end:                                           ; preds = %entry
42  ret i64 0
43}
44
45; Verify that we don't attempt to use the compare and trap
46; instruction with an index operand.
47define i32 @f3(i32 zeroext %a, i32 *%base, i64 %offset) {
48; CHECK-LABEL: f3:
49; CHECK: cl %r2, 0(%r{{[0-5]}},%r3)
50; CHECK: lhi %r2, 0
51; CHECK-LABEL: .Ltmp0
52; CHECK: jh .Ltmp0+2
53; CHECK: br %r14
54entry:
55  %ptr = getelementptr i32, i32 *%base, i64 %offset
56  %b = load i32, i32 *%ptr
57  %cmp = icmp ugt i32 %a, %b
58  br i1 %cmp, label %if.then, label %if.end
59
60if.then:                                          ; preds = %entry
61  tail call void @llvm.trap()
62  unreachable
63
64if.end:                                           ; preds = %entry
65  ret i32 0
66}
67
68; Verify that we don't attempt to use the compare and trap grande
69; instruction with an index operand.
70define i64 @f4(i64 %a, i64 *%base, i64 %offset) {
71; CHECK-LABEL: f4:
72; CHECK: clg %r2, 0(%r{{[0-5]}},%r3)
73; CHECK: lghi %r2, 0
74; CHECK-LABEL: .Ltmp1
75; CHECK: jh .Ltmp1+2
76; CHECK: br %r14
77entry:
78  %ptr = getelementptr i64, i64 *%base, i64 %offset
79  %b = load i64, i64 *%ptr
80  %cmp = icmp ugt i64 %a, %b
81  br i1 %cmp, label %if.then, label %if.end
82
83if.then:                                          ; preds = %entry
84  tail call void @llvm.trap()
85  unreachable
86
87if.end:                                           ; preds = %entry
88  ret i64 0
89}
90
91