1; Test LOCHI and LOCGHI.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 -verify-machineinstrs | FileCheck %s
4;
5; Run the test again to make sure it still works the same even
6; in the presence of the select instructions.
7; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z15 -verify-machineinstrs | FileCheck %s
8
9
10define i32 @f1(i32 %x) {
11; CHECK-LABEL: f1:
12; CHECK: chi %r2, 0
13; CHECK: lhi %r2, 0
14; CHECK: lochilh %r2, 42
15; CHECK: br %r14
16  %cond = icmp ne i32 %x, 0
17  %res = select i1 %cond, i32 42, i32 0
18  ret i32 %res
19}
20
21define i32 @f2(i32 %x, i32 %y) {
22; CHECK-LABEL: f2:
23; CHECK: chi %r2, 0
24; CHECK: lochilh %r3, 42
25; CHECK: br %r14
26  %cond = icmp ne i32 %x, 0
27  %res = select i1 %cond, i32 42, i32 %y
28  ret i32 %res
29}
30
31define i32 @f3(i32 %x, i32 %y) {
32; CHECK-LABEL: f3:
33; CHECK: chi %r2, 0
34; CHECK: lochie %r3, 42
35; CHECK: br %r14
36  %cond = icmp ne i32 %x, 0
37  %res = select i1 %cond, i32 %y, i32 42
38  ret i32 %res
39}
40
41define i64 @f4(i64 %x) {
42; CHECK-LABEL: f4:
43; CHECK: cghi %r2, 0
44; CHECK: lghi %r2, 0
45; CHECK: locghilh %r2, 42
46; CHECK: br %r14
47  %cond = icmp ne i64 %x, 0
48  %res = select i1 %cond, i64 42, i64 0
49  ret i64 %res
50}
51
52define i64 @f5(i64 %x, i64 %y) {
53; CHECK-LABEL: f5:
54; CHECK: cghi %r2, 0
55; CHECK: locghilh %r3, 42
56; CHECK: br %r14
57  %cond = icmp ne i64 %x, 0
58  %res = select i1 %cond, i64 42, i64 %y
59  ret i64 %res
60}
61
62define i64 @f6(i64 %x, i64 %y) {
63; CHECK-LABEL: f6:
64; CHECK: cghi %r2, 0
65; CHECK: locghie %r3, 42
66; CHECK: br %r14
67  %cond = icmp ne i64 %x, 0
68  %res = select i1 %cond, i64 %y, i64 42
69  ret i64 %res
70}
71
72; Check that we also get LOCHI as a result of early if-conversion.
73define i32 @f7(i32 %x, i32 %y) {
74; CHECK-LABEL: f7:
75; CHECK: chi %r2, 0
76; CHECK: lochie %r3, 42
77; CHECK: br %r14
78entry:
79  %cond = icmp ne i32 %x, 0
80  br i1 %cond, label %if.then, label %return
81
82if.then:
83  br label %return
84
85return:
86  %res = phi i32 [ %y, %if.then ], [ 42, %entry ]
87  ret i32 %res
88}
89
90; ... and the same for LOCGHI.
91define i64 @f8(i64 %x, i64 %y) {
92; CHECK-LABEL: f8:
93; CHECK: cghi %r2, 0
94; CHECK: locghie %r3, 42
95; CHECK: br %r14
96entry:
97  %cond = icmp ne i64 %x, 0
98  br i1 %cond, label %if.then, label %return
99
100if.then:
101  br label %return
102
103return:
104  %res = phi i64 [ %y, %if.then ], [ 42, %entry ]
105  ret i64 %res
106}
107
108; Check that inverting the condition works as well.
109define i32 @f9(i32 %x, i32 %y) {
110; CHECK-LABEL: f9:
111; CHECK: chi %r2, 0
112; CHECK: lochilh %r3, 42
113; CHECK: br %r14
114entry:
115  %cond = icmp ne i32 %x, 0
116  br i1 %cond, label %if.then, label %return
117
118if.then:
119  br label %return
120
121return:
122  %res = phi i32 [ 42, %if.then ], [ %y, %entry ]
123  ret i32 %res
124}
125
126; ... and the same for LOCGHI.
127define i64 @f10(i64 %x, i64 %y) {
128; CHECK-LABEL: f10:
129; CHECK: cghi %r2, 0
130; CHECK: locghilh %r3, 42
131; CHECK: br %r14
132entry:
133  %cond = icmp ne i64 %x, 0
134  br i1 %cond, label %if.then, label %return
135
136if.then:
137  br label %return
138
139return:
140  %res = phi i64 [ 42, %if.then ], [ %y, %entry ]
141  ret i64 %res
142}
143
144