1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
4 define float @select_max_ugt(float %a, float %b) {
5 ; CHECK-LABEL: @select_max_ugt(
6 ; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp arcp ole float [[A:%.*]], [[B:%.*]]
7 ; CHECK-NEXT: [[SEL:%.*]] = select arcp i1 [[CMP_INV]], float [[B]], float [[A]]
8 ; CHECK-NEXT: ret float [[SEL]]
10 %cmp = fcmp arcp ugt float %a, %b
11 %sel = select arcp i1 %cmp, float %a, float %b
15 define float @select_max_uge(float %a, float %b) {
16 ; CHECK-LABEL: @select_max_uge(
17 ; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp nnan olt float [[A:%.*]], [[B:%.*]]
18 ; CHECK-NEXT: [[SEL:%.*]] = select nnan i1 [[CMP_INV]], float [[B]], float [[A]]
19 ; CHECK-NEXT: ret float [[SEL]]
21 %cmp = fcmp nnan uge float %a, %b
22 %sel = select ninf i1 %cmp, float %a, float %b
26 define float @select_min_ugt(float %a, float %b) {
27 ; CHECK-LABEL: @select_min_ugt(
28 ; CHECK-NEXT: [[SEL:%.*]] = call fast float @llvm.minnum.f32(float [[A:%.*]], float [[B:%.*]])
29 ; CHECK-NEXT: ret float [[SEL]]
31 %cmp = fcmp fast ugt float %a, %b
32 %sel = select reassoc i1 %cmp, float %b, float %a
36 define float @select_min_uge(float %a, float %b) {
37 ; CHECK-LABEL: @select_min_uge(
38 ; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp nsz olt float [[A:%.*]], [[B:%.*]]
39 ; CHECK-NEXT: [[SEL:%.*]] = select nsz i1 [[CMP_INV]], float [[A]], float [[B]]
40 ; CHECK-NEXT: ret float [[SEL]]
42 %cmp = fcmp nsz uge float %a, %b
43 %sel = select fast i1 %cmp, float %b, float %a
47 define float @select_max_ult(float %a, float %b) {
48 ; CHECK-LABEL: @select_max_ult(
49 ; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp arcp oge float [[A:%.*]], [[B:%.*]]
50 ; CHECK-NEXT: [[SEL:%.*]] = select arcp i1 [[CMP_INV]], float [[A]], float [[B]]
51 ; CHECK-NEXT: ret float [[SEL]]
53 %cmp = fcmp arcp ult float %a, %b
54 %sel = select ninf nnan i1 %cmp, float %b, float %a
58 define float @select_max_ule(float %a, float %b) {
59 ; CHECK-LABEL: @select_max_ule(
60 ; CHECK-NEXT: [[SEL:%.*]] = call fast float @llvm.maxnum.f32(float [[A:%.*]], float [[B:%.*]])
61 ; CHECK-NEXT: ret float [[SEL]]
63 %cmp = fcmp fast ule float %a, %b
64 %sel = select nsz i1 %cmp, float %b, float %a
68 define float @select_min_ult(float %a, float %b) {
69 ; CHECK-LABEL: @select_min_ult(
70 ; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp nsz oge float [[A:%.*]], [[B:%.*]]
71 ; CHECK-NEXT: [[SEL:%.*]] = select nsz i1 [[CMP_INV]], float [[B]], float [[A]]
72 ; CHECK-NEXT: ret float [[SEL]]
74 %cmp = fcmp nsz ult float %a, %b
75 %sel = select fast i1 %cmp, float %a, float %b
79 define float @select_min_ule(float %a, float %b) {
80 ; CHECK-LABEL: @select_min_ule(
81 ; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp arcp ogt float [[A:%.*]], [[B:%.*]]
82 ; CHECK-NEXT: [[SEL:%.*]] = select arcp i1 [[CMP_INV]], float [[B]], float [[A]]
83 ; CHECK-NEXT: ret float [[SEL]]
85 %cmp = fcmp arcp ule float %a, %b
86 %sel = select ninf i1 %cmp, float %a, float %b
90 define float @select_fcmp_une(float %a, float %b) {
91 ; CHECK-LABEL: @select_fcmp_une(
92 ; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp reassoc oeq float [[A:%.*]], [[B:%.*]]
93 ; CHECK-NEXT: [[SEL:%.*]] = select reassoc i1 [[CMP_INV]], float [[B]], float [[A]]
94 ; CHECK-NEXT: ret float [[SEL]]
96 %cmp = fcmp reassoc une float %a, %b
97 %sel = select nnan i1 %cmp, float %a, float %b
101 define float @select_fcmp_ueq(float %a, float %b) {
102 ; CHECK-LABEL: @select_fcmp_ueq(
103 ; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp reassoc one float [[A:%.*]], [[B:%.*]]
104 ; CHECK-NEXT: [[SEL:%.*]] = select reassoc i1 [[CMP_INV]], float [[B]], float [[A]]
105 ; CHECK-NEXT: ret float [[SEL]]
107 %cmp = fcmp reassoc ueq float %a, %b
108 %sel = select arcp nnan i1 %cmp, float %a, float %b
112 declare void @foo(i1)
114 define float @select_max_ugt_2_use_cmp(float %a, float %b) {
115 ; CHECK-LABEL: @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]]
121 %cmp = fcmp reassoc ugt float %a, %b
122 call void @foo(i1 %cmp)
123 %sel = select fast i1 %cmp, float %a, float %b
127 define float @select_min_uge_2_use_cmp(float %a, float %b) {
128 ; CHECK-LABEL: @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]]
134 %cmp = fcmp ninf uge float %a, %b
135 call void @foo(i1 %cmp)
136 %sel = select nsz i1 %cmp, float %b, float %a