• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; Test LOCR and LOCGR.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z196 -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 load-store-on-condition-2 facility.
7; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 -verify-machineinstrs | FileCheck %s
8
9; Test LOCR.
10define i32 @f1(i32 %a, i32 %b, i32 %limit) {
11; CHECK-LABEL: f1:
12; CHECK: clfi %r4, 42
13; CHECK: locrhe %r2, %r3
14; CHECK: br %r14
15  %cond = icmp ult i32 %limit, 42
16  %res = select i1 %cond, i32 %a, i32 %b
17  ret i32 %res
18}
19
20; Test LOCGR.
21define i64 @f2(i64 %a, i64 %b, i64 %limit) {
22; CHECK-LABEL: f2:
23; CHECK: clgfi %r4, 42
24; CHECK: locgrhe %r2, %r3
25; CHECK: br %r14
26  %cond = icmp ult i64 %limit, 42
27  %res = select i1 %cond, i64 %a, i64 %b
28  ret i64 %res
29}
30
31; Test LOCR in a case that could use COMPARE AND BRANCH.  We prefer using
32; LOCR if possible.
33define i32 @f3(i32 %a, i32 %b, i32 %limit) {
34; CHECK-LABEL: f3:
35; CHECK: chi %r4, 42
36; CHECK: locrlh %r2, %r3
37; CHECK: br %r14
38  %cond = icmp eq i32 %limit, 42
39  %res = select i1 %cond, i32 %a, i32 %b
40  ret i32 %res
41}
42
43; ...and again for LOCGR.
44define i64 @f4(i64 %a, i64 %b, i64 %limit) {
45; CHECK-LABEL: f4:
46; CHECK: cghi %r4, 42
47; CHECK: locgrlh %r2, %r3
48; CHECK: br %r14
49  %cond = icmp eq i64 %limit, 42
50  %res = select i1 %cond, i64 %a, i64 %b
51  ret i64 %res
52}
53
54; Check that we also get LOCR as a result of early if-conversion.
55define i32 @f5(i32 %a, i32 %b, i32 %limit) {
56; CHECK-LABEL: f5:
57; CHECK: clfi %r4, 41
58; CHECK: locrh %r2, %r3
59; CHECK: br %r14
60entry:
61  %cond = icmp ult i32 %limit, 42
62  br i1 %cond, label %if.then, label %return
63
64if.then:
65  br label %return
66
67return:
68  %res = phi i32 [ %a, %if.then ], [ %b, %entry ]
69  ret i32 %res
70}
71
72; ... and likewise for LOCGR.
73define i64 @f6(i64 %a, i64 %b, i64 %limit) {
74; CHECK-LABEL: f6:
75; CHECK: clgfi %r4, 41
76; CHECK: locgrh %r2, %r3
77; CHECK: br %r14
78entry:
79  %cond = icmp ult i64 %limit, 42
80  br i1 %cond, label %if.then, label %return
81
82if.then:
83  br label %return
84
85return:
86  %res = phi i64 [ %a, %if.then ], [ %b, %entry ]
87  ret i64 %res
88}
89
90; Check that inverting the condition works as well.
91define i32 @f7(i32 %a, i32 %b, i32 %limit) {
92; CHECK-LABEL: f7:
93; CHECK: clfi %r4, 41
94; CHECK: locrle %r2, %r3
95; CHECK: br %r14
96entry:
97  %cond = icmp ult i32 %limit, 42
98  br i1 %cond, label %if.then, label %return
99
100if.then:
101  br label %return
102
103return:
104  %res = phi i32 [ %b, %if.then ], [ %a, %entry ]
105  ret i32 %res
106}
107
108; ... and likewise for LOCGR.
109define i64 @f8(i64 %a, i64 %b, i64 %limit) {
110; CHECK-LABEL: f8:
111; CHECK: clgfi %r4, 41
112; CHECK: locgrle %r2, %r3
113; CHECK: br %r14
114entry:
115  %cond = icmp ult i64 %limit, 42
116  br i1 %cond, label %if.then, label %return
117
118if.then:
119  br label %return
120
121return:
122  %res = phi i64 [ %b, %if.then ], [ %a, %entry ]
123  ret i64 %res
124}
125
126