1; Test that multiple select statements using the same condition are expanded
2; into a single conditional branch when possible.
3;
4; RUN: llc < %s -mtriple=s390x-linux-gnu -disable-block-placement | FileCheck %s
5
6define void @test0(i32 signext %positive, double %base, double %offset, double* %rmin, double* %rmax) {
7entry:
8; CHECK-LABEL: test0
9; CHECK: cijlh %r2, 0,
10; CHECK-NOT: cij
11; CHECK-NOT: je
12; CHECK-NOT: jlh
13
14  %tobool = icmp eq i32 %positive, 0
15  %add = fadd double %base, %offset
16  %min = select i1 %tobool, double %add, double %base
17  %max = select i1 %tobool, double %base, double %add
18  store double %min, double* %rmin, align 8
19  store double %max, double* %rmax, align 8
20  ret void
21}
22
23; Two selects with an intervening instruction that doesn't clobber CC can
24; still be merged.
25define double @test1(i32 signext %positive, double %A, double %B, double %C) {
26entry:
27; CHECK-LABEL: test1
28; CHECK: cijhe {{.*}}LBB1_2
29; CHECK-NOT: cij
30; CHECK: br %r14
31
32  %tobool = icmp slt i32 %positive, 0
33  %s1  = select i1 %tobool, double %A, double %B
34  %mul = fmul double %A, %B
35  %s2  = select i1 %tobool, double %B, double %C
36  %add = fadd double %s1, %s2
37  %add2 = fadd double %add, %mul
38  ret double %add2
39}
40
41; Two selects with an intervening user of the first select can't be merged.
42define double @test2(i32 signext %positive, double %A, double %B) {
43entry:
44; CHECK-LABEL: test2
45; CHECK: cije {{.*}}LBB2_2
46; CHECK: cibe {{.*}}%r14
47; CHECK: br %r14
48
49  %tobool = icmp eq i32 %positive, 0
50  %s1  = select i1 %tobool, double %A, double %B
51  %add = fadd double %A, %s1
52  %s2  = select i1 %tobool, double %A, double %add
53  ret double %s2
54}
55
56; Two selects with different conditions can't be merged
57define double @test3(i32 signext %positive, double %A, double %B, double %C) {
58entry:
59; CHECK-LABEL: test3
60; CHECK: cijl {{.*}}LBB3_2
61; CHECK: cijl {{.*}}LBB3_4
62; CHECK: br %r14
63
64  %tobool = icmp slt i32 %positive, 0
65  %s1  = select i1 %tobool, double %A, double %B
66  %tobool2 = icmp slt i32 %positive, 2
67  %s2  = select i1 %tobool2, double %B, double %C
68  %add = fadd double %s1, %s2
69  ret double %add
70}
71