1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -instcombine < %s | FileCheck %s
3
4define float @select_max_ugt(float %a, float %b) {
5; CHECK-LABEL: define {{[^@]+}}@select_max_ugt(
6; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp arcp ole float [[A:%.*]], [[B:%.*]]
7; CHECK-NEXT:    [[TMP1:%.*]] = select arcp i1 [[CMP_INV]], float [[B]], float [[A]]
8; CHECK-NEXT:    ret float [[TMP1]]
9;
10  %cmp = fcmp arcp ugt float %a, %b
11  %sel = select arcp i1 %cmp, float %a, float %b
12  ret float %sel
13}
14
15define float @select_max_uge(float %a, float %b) {
16; CHECK-LABEL: define {{[^@]+}}@select_max_uge(
17; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp nnan olt float [[A:%.*]], [[B:%.*]]
18; CHECK-NEXT:    [[TMP1:%.*]] = select nnan i1 [[CMP_INV]], float [[B]], float [[A]]
19; CHECK-NEXT:    ret float [[TMP1]]
20;
21  %cmp = fcmp nnan uge float %a, %b
22  %sel = select ninf i1 %cmp, float %a, float %b
23  ret float %sel
24}
25
26define float @select_min_ugt(float %a, float %b) {
27; CHECK-LABEL: define {{[^@]+}}@select_min_ugt(
28; CHECK-NEXT:    [[TMP1:%.*]] = call fast float @llvm.minnum.f32(float [[A:%.*]], float [[B:%.*]])
29; CHECK-NEXT:    ret float [[TMP1]]
30;
31  %cmp = fcmp fast ugt float %a, %b
32  %sel = select reassoc i1 %cmp, float %b, float %a
33  ret float %sel
34}
35
36define float @select_min_uge(float %a, float %b) {
37; CHECK-LABEL: define {{[^@]+}}@select_min_uge(
38; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp nsz olt float [[A:%.*]], [[B:%.*]]
39; CHECK-NEXT:    [[TMP1:%.*]] = select nsz i1 [[CMP_INV]], float [[A]], float [[B]]
40; CHECK-NEXT:    ret float [[TMP1]]
41;
42  %cmp = fcmp nsz uge float %a, %b
43  %sel = select fast i1 %cmp, float %b, float %a
44  ret float %sel
45}
46
47define float @select_max_ult(float %a, float %b) {
48; CHECK-LABEL: define {{[^@]+}}@select_max_ult(
49; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp arcp oge float [[A:%.*]], [[B:%.*]]
50; CHECK-NEXT:    [[TMP1:%.*]] = select arcp i1 [[CMP_INV]], float [[A]], float [[B]]
51; CHECK-NEXT:    ret float [[TMP1]]
52;
53  %cmp = fcmp arcp ult float %a, %b
54  %sel = select ninf nnan i1 %cmp, float %b, float %a
55  ret float %sel
56}
57
58define float @select_max_ule(float %a, float %b) {
59; CHECK-LABEL: define {{[^@]+}}@select_max_ule(
60; CHECK-NEXT:    [[TMP1:%.*]] = call fast float @llvm.maxnum.f32(float [[A:%.*]], float [[B:%.*]])
61; CHECK-NEXT:    ret float [[TMP1]]
62;
63  %cmp = fcmp fast ule float %a, %b
64  %sel = select nsz i1 %cmp, float %b, float %a
65  ret float %sel
66}
67
68define float @select_min_ult(float %a, float %b) {
69; CHECK-LABEL: define {{[^@]+}}@select_min_ult(
70; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp nsz oge float [[A:%.*]], [[B:%.*]]
71; CHECK-NEXT:    [[TMP1:%.*]] = select nsz i1 [[CMP_INV]], float [[B]], float [[A]]
72; CHECK-NEXT:    ret float [[TMP1]]
73;
74  %cmp = fcmp nsz ult float %a, %b
75  %sel = select fast i1 %cmp, float %a, float %b
76  ret float %sel
77}
78
79define float @select_min_ule(float %a, float %b) {
80; CHECK-LABEL: define {{[^@]+}}@select_min_ule(
81; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp arcp ogt float [[A:%.*]], [[B:%.*]]
82; CHECK-NEXT:    [[TMP1:%.*]] = select arcp i1 [[CMP_INV]], float [[B]], float [[A]]
83; CHECK-NEXT:    ret float [[TMP1]]
84;
85  %cmp = fcmp arcp ule float %a, %b
86  %sel = select ninf i1 %cmp, float %a, float %b
87  ret float %sel
88}
89
90define float @select_fcmp_une(float %a, float %b) {
91; CHECK-LABEL: define {{[^@]+}}@select_fcmp_une(
92; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp reassoc oeq float [[A:%.*]], [[B:%.*]]
93; CHECK-NEXT:    [[TMP1:%.*]] = select reassoc i1 [[CMP_INV]], float [[B]], float [[A]]
94; CHECK-NEXT:    ret float [[TMP1]]
95;
96  %cmp = fcmp reassoc une float %a, %b
97  %sel = select nnan i1 %cmp, float %a, float %b
98  ret float %sel
99}
100
101define float @select_fcmp_ueq(float %a, float %b) {
102; CHECK-LABEL: define {{[^@]+}}@select_fcmp_ueq(
103; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp reassoc one float [[A:%.*]], [[B:%.*]]
104; CHECK-NEXT:    [[TMP1:%.*]] = select reassoc i1 [[CMP_INV]], float [[B]], float [[A]]
105; CHECK-NEXT:    ret float [[TMP1]]
106;
107  %cmp = fcmp reassoc ueq float %a, %b
108  %sel = select arcp nnan i1 %cmp, float %a, float %b
109  ret float %sel
110}
111
112declare void @foo(i1)
113
114define float @select_max_ugt_2_use_cmp(float %a, float %b) {
115; CHECK-LABEL: define {{[^@]+}}@select_max_ugt_2_use_cmp(
116; CHECK-NEXT:    [[CMP:%.*]] = fcmp reassoc ugt float [[A:%.*]], [[B:%.*]]
117; CHECK-NEXT:    call void @foo(i1 [[CMP]])
118; CHECK-NEXT:    [[SEL:%.*]] = select fast i1 [[CMP]], float [[A]], float [[B]]
119; CHECK-NEXT:    ret float [[SEL]]
120;
121  %cmp = fcmp reassoc ugt float %a, %b
122  call void @foo(i1 %cmp)
123  %sel = select fast i1 %cmp, float %a, float %b
124  ret float %sel
125}
126
127define float @select_min_uge_2_use_cmp(float %a, float %b) {
128; CHECK-LABEL: define {{[^@]+}}@select_min_uge_2_use_cmp(
129; CHECK-NEXT:    [[CMP:%.*]] = fcmp ninf uge float [[A:%.*]], [[B:%.*]]
130; CHECK-NEXT:    call void @foo(i1 [[CMP]])
131; CHECK-NEXT:    [[SEL:%.*]] = select nsz i1 [[CMP]], float [[B]], float [[A]]
132; CHECK-NEXT:    ret float [[SEL]]
133;
134  %cmp = fcmp ninf uge float %a, %b
135  call void @foo(i1 %cmp)
136  %sel = select nsz i1 %cmp, float %b, float %a
137  ret float %sel
138}
139