1; RUN: llc < %s -mtriple=arm64-- | FileCheck %s
2
3; This test provides fmf coverage for DAG combining of selects
4
5; CHECK-LABEL: select_select_fold_select_and
6; CHECK:         fminnm	s1, s1, s2
7; CHECK-NEXT:    fmaxnm	s2, s0, s3
8; CHECK-NEXT:    fmov
9; CHECK-NEXT:    fccmp	s1, s0, #4, lt
10; CHECK-NEXT:    fcsel	s2, s2, s0, gt
11
12; select Cond0, (select Cond1, X, Y), Y -> select (and Cond0, Cond1), X, Y
13define float @select_select_fold_select_and(float %w, float %x, float %y, float %z) {
14  %tmp21 = fcmp fast olt float %x, %y
15  %tmp22 = select fast i1 %tmp21, float %x, float %y
16  %tmp24 = fcmp fast ogt float %tmp22, %w
17  %tmp78 = fcmp fast ogt float %w, %z
18  %select0 = select fast i1 %tmp78, float %w, float %z
19  %select1 = select fast i1 %tmp21, float %select0, float %w
20  %select2 = select fast i1 %tmp24, float %select1, float %w
21  %tmp82 = fadd fast float %w, 5.000000e-01
22  %tmp102 = fadd fast float %tmp82, %select2
23  %cmp.i155.i.i = fcmp fast ogt float %tmp102, %tmp82
24  br i1 %cmp.i155.i.i, label %if.then.i157.i.i, label %if.end.i159.i.i
25
26if.then.i157.i.i:                                 ; preds = %0
27  %add.i156.i.i = fadd fast float %select2, 1.000000e+00
28  br label %exit
29
30if.end.i159.i.i:                                  ; preds = %0
31  %sub.i158.i.i = fadd fast float %w, 0xBFD99999A0000000
32  %sub15.i.i.i = fadd fast float %z, 0xBFD6666660000000
33  %tmp191 = fcmp fast ogt float %tmp82, 0.000000e+00
34  %select3 = select fast i1 %tmp191, float %sub.i158.i.i, float %sub15.i.i.i
35  br label %exit
36
37exit:                                     ; preds = %if.end.i159.i.i, %if.then.i157.i.i
38  %phi1 = phi float [ %add.i156.i.i, %if.then.i157.i.i ], [ %select3, %if.end.i159.i.i ]
39  ret float %phi1
40}
41
42; CHECK-LABEL: select_select_fold_select_or
43; CHECK:         fcmp	s1, s2
44; CHECK-NEXT:    fminnm	s1, s1, s2
45; CHECK-NEXT:    fmaxnm	s2, s0, s3
46; CHECK-NEXT:    fmov
47; CHECK-NEXT:    fccmp	s1, s0, #0, ge
48; CHECK-NEXT:    fcsel	s2, s0, s2, gt
49
50; select Cond0, X, (select Cond1, X, Y) -> select (or Cond0, Cond1), X, Y
51define float @select_select_fold_select_or(float %w, float %x, float %y, float %z) {
52  %tmp21 = fcmp fast olt float %x, %y
53  %tmp22 = select fast i1 %tmp21, float %x, float %y
54  %tmp24 = fcmp fast ogt float %tmp22, %w
55  %tmp78 = fcmp fast ogt float %w, %z
56  %select0 = select fast i1 %tmp78, float %w, float %z
57  %select1 = select fast i1 %tmp21, float %w, float %select0
58  %select2 = select fast i1 %tmp24, float %w, float %select1
59  %tmp82 = fadd fast float %w, 5.000000e-01
60  %tmp102 = fadd fast float %tmp82, %select2
61  %cmp.i155.i.i = fcmp fast ogt float %tmp102, %tmp82
62  br i1 %cmp.i155.i.i, label %if.then.i157.i.i, label %if.end.i159.i.i
63
64if.then.i157.i.i:                                 ; preds = %0
65  %add.i156.i.i = fadd fast float %select2, 1.000000e+00
66  br label %exit
67
68if.end.i159.i.i:                                  ; preds = %0
69  %sub.i158.i.i = fadd fast float %w, 0xBFD99999A0000000
70  %sub15.i.i.i = fadd fast float %z, 0xBFD6666660000000
71  %tmp191 = fcmp fast ogt float %tmp82, 0.000000e+00
72  %select3 = select fast i1 %tmp191, float %sub.i158.i.i, float %sub15.i.i.i
73  br label %exit
74
75exit:                                     ; preds = %if.end.i159.i.i, %if.then.i157.i.i
76  %phi1 = phi float [ %add.i156.i.i, %if.then.i157.i.i ], [ %select3, %if.end.i159.i.i ]
77  ret float %phi1
78}
79