Skip to content

Commit 3d6b539

Browse files
committed
[InstCombine] propagate fast-math-flags (FMF) to select when inverting fcmp+select
As noted by the FIXME comment, this is not correct based on our current FMF semantics. We should be propagating FMF from the final value in a sequence (in this case the 'select'). So the behavior even without this patch is wrong, but we did not allow FMF on 'select' until recently. But if we do the correct thing right now in this patch, we'll inevitably introduce regressions because we have not wired up FMF propagation for 'phi' and 'select' in other passes (like SimplifyCFG) or other places in InstCombine. I'm not seeing a better incremental way to make progress. That said, the potential extra damage over the existing wrong behavior from this patch is very limited. AFAIK, the only way to have different FMF on IR in the same function is if we have LTO inlined IR from 2 modules that were compiled using different fast-math settings. As seen in the tests, we may actually see some improvements with this patch because adding the FMF to the 'select' allows matching to min/max intrinsics that were previously missed (in the common case, the 'fcmp' and 'select' should have identical FMF to begin with). Next steps in the transition: Make similar changes in instcombine as needed. Enable phi-to-select FMF propagation in SimplifyCFG. Remove dependencies on fcmp with FMF. Deprecate FMF on fcmp. Differential Revision: https://reviews.llvm.org/D69720
1 parent 1eea3fa commit 3d6b539

File tree

5 files changed

+64
-75
lines changed

5 files changed

+64
-75
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,12 +2344,12 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
23442344
if (FCI->hasOneUse() && FCmpInst::isUnordered(FCI->getPredicate())) {
23452345
FCmpInst::Predicate InvPred = FCI->getInversePredicate();
23462346
IRBuilder<>::FastMathFlagGuard FMFG(Builder);
2347+
// FIXME: The FMF should propagate from the select, not the fcmp.
23472348
Builder.setFastMathFlags(FCI->getFastMathFlags());
23482349
Value *NewCond = Builder.CreateFCmp(InvPred, Cmp0, Cmp1,
23492350
FCI->getName() + ".inv");
2350-
2351-
return SelectInst::Create(NewCond, FalseVal, TrueVal,
2352-
SI.getName() + ".p");
2351+
Value *NewSel = Builder.CreateSelect(NewCond, FalseVal, TrueVal);
2352+
return replaceInstUsesWith(SI, NewSel);
23532353
}
23542354

23552355
// NOTE: if we wanted to, this is where to detect MIN/MAX

llvm/test/Transforms/InstCombine/clamp-to-minmax.ll

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ define float @clamp_float_fast_ordered_strict_maxmin(float %x) {
66
; CHECK-LABEL: define {{[^@]+}}@clamp_float_fast_ordered_strict_maxmin(
77
; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
88
; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
9-
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+00
10-
; CHECK-NEXT: [[R1:%.*]] = select i1 [[DOTINV]], float [[MIN]], float 1.000000e+00
11-
; CHECK-NEXT: ret float [[R1]]
9+
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.maxnum.f32(float [[MIN]], float 1.000000e+00)
10+
; CHECK-NEXT: ret float [[TMP1]]
1211
;
1312
%cmp2 = fcmp fast olt float %x, 255.0
1413
%min = select i1 %cmp2, float %x, float 255.0
@@ -22,9 +21,8 @@ define float @clamp_float_fast_ordered_nonstrict_maxmin(float %x) {
2221
; CHECK-LABEL: define {{[^@]+}}@clamp_float_fast_ordered_nonstrict_maxmin(
2322
; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
2423
; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
25-
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+00
26-
; CHECK-NEXT: [[R1:%.*]] = select i1 [[DOTINV]], float [[MIN]], float 1.000000e+00
27-
; CHECK-NEXT: ret float [[R1]]
24+
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.maxnum.f32(float [[MIN]], float 1.000000e+00)
25+
; CHECK-NEXT: ret float [[TMP1]]
2826
;
2927
%cmp2 = fcmp fast olt float %x, 255.0
3028
%min = select i1 %cmp2, float %x, float 255.0
@@ -38,9 +36,8 @@ define float @clamp_float_fast_ordered_strict_minmax(float %x) {
3836
; CHECK-LABEL: define {{[^@]+}}@clamp_float_fast_ordered_strict_minmax(
3937
; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast ogt float [[X:%.*]], 1.000000e+00
4038
; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
41-
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+02
42-
; CHECK-NEXT: [[R1:%.*]] = select i1 [[DOTINV]], float [[MAX]], float 2.550000e+02
43-
; CHECK-NEXT: ret float [[R1]]
39+
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.minnum.f32(float [[MAX]], float 2.550000e+02)
40+
; CHECK-NEXT: ret float [[TMP1]]
4441
;
4542
%cmp2 = fcmp fast ogt float %x, 1.0
4643
%max = select i1 %cmp2, float %x, float 1.0
@@ -54,9 +51,8 @@ define float @clamp_float_fast_ordered_nonstrict_minmax(float %x) {
5451
; CHECK-LABEL: define {{[^@]+}}@clamp_float_fast_ordered_nonstrict_minmax(
5552
; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast ogt float [[X:%.*]], 1.000000e+00
5653
; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
57-
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+02
58-
; CHECK-NEXT: [[R1:%.*]] = select i1 [[DOTINV]], float [[MAX]], float 2.550000e+02
59-
; CHECK-NEXT: ret float [[R1]]
54+
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.minnum.f32(float [[MAX]], float 2.550000e+02)
55+
; CHECK-NEXT: ret float [[TMP1]]
6056
;
6157
%cmp2 = fcmp fast ogt float %x, 1.0
6258
%max = select i1 %cmp2, float %x, float 1.0
@@ -72,10 +68,9 @@ define float @clamp_float_fast_ordered_nonstrict_minmax(float %x) {
7268
define float @clamp_float_fast_unordered_strict_maxmin(float %x) {
7369
; CHECK-LABEL: define {{[^@]+}}@clamp_float_fast_unordered_strict_maxmin(
7470
; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
75-
; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
76-
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+00
77-
; CHECK-NEXT: [[R1:%.*]] = select i1 [[DOTINV]], float [[MIN]], float 1.000000e+00
78-
; CHECK-NEXT: ret float [[R1]]
71+
; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
72+
; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.maxnum.f32(float [[TMP1]], float 1.000000e+00)
73+
; CHECK-NEXT: ret float [[TMP2]]
7974
;
8075
%cmp2 = fcmp fast ult float %x, 255.0
8176
%min = select i1 %cmp2, float %x, float 255.0
@@ -88,10 +83,9 @@ define float @clamp_float_fast_unordered_strict_maxmin(float %x) {
8883
define float @clamp_float_fast_unordered_nonstrict_maxmin(float %x) {
8984
; CHECK-LABEL: define {{[^@]+}}@clamp_float_fast_unordered_nonstrict_maxmin(
9085
; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
91-
; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
92-
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+00
93-
; CHECK-NEXT: [[R1:%.*]] = select i1 [[DOTINV]], float [[MIN]], float 1.000000e+00
94-
; CHECK-NEXT: ret float [[R1]]
86+
; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
87+
; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.maxnum.f32(float [[TMP1]], float 1.000000e+00)
88+
; CHECK-NEXT: ret float [[TMP2]]
9589
;
9690
%cmp2 = fcmp fast ult float %x, 255.0
9791
%min = select i1 %cmp2, float %x, float 255.0
@@ -104,10 +98,9 @@ define float @clamp_float_fast_unordered_nonstrict_maxmin(float %x) {
10498
define float @clamp_float_fast_unordered_strict_minmax(float %x) {
10599
; CHECK-LABEL: define {{[^@]+}}@clamp_float_fast_unordered_strict_minmax(
106100
; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp fast ole float [[X:%.*]], 1.000000e+00
107-
; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
108-
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+02
109-
; CHECK-NEXT: [[R1:%.*]] = select i1 [[DOTINV]], float [[MAX]], float 2.550000e+02
110-
; CHECK-NEXT: ret float [[R1]]
101+
; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
102+
; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.minnum.f32(float [[TMP1]], float 2.550000e+02)
103+
; CHECK-NEXT: ret float [[TMP2]]
111104
;
112105
%cmp2 = fcmp fast ugt float %x, 1.0
113106
%max = select i1 %cmp2, float %x, float 1.0
@@ -120,10 +113,9 @@ define float @clamp_float_fast_unordered_strict_minmax(float %x) {
120113
define float @clamp_float_fast_unordered_nonstrict_minmax(float %x) {
121114
; CHECK-LABEL: define {{[^@]+}}@clamp_float_fast_unordered_nonstrict_minmax(
122115
; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp fast ole float [[X:%.*]], 1.000000e+00
123-
; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
124-
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+02
125-
; CHECK-NEXT: [[R1:%.*]] = select i1 [[DOTINV]], float [[MAX]], float 2.550000e+02
126-
; CHECK-NEXT: ret float [[R1]]
116+
; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
117+
; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.minnum.f32(float [[TMP1]], float 2.550000e+02)
118+
; CHECK-NEXT: ret float [[TMP2]]
127119
;
128120
%cmp2 = fcmp fast ugt float %x, 1.0
129121
%max = select i1 %cmp2, float %x, float 1.0
@@ -139,10 +131,9 @@ define float @clamp_float_fast_unordered_nonstrict_minmax(float %x) {
139131
define float @clamp_test_1(float %x) {
140132
; CHECK-LABEL: define {{[^@]+}}@clamp_test_1(
141133
; CHECK-NEXT: [[INNER_CMP_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
142-
; CHECK-NEXT: [[INNER_SEL:%.*]] = select i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]
143-
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast oge float [[INNER_SEL]], 1.000000e+00
144-
; CHECK-NEXT: [[R1:%.*]] = select i1 [[DOTINV]], float [[INNER_SEL]], float 1.000000e+00
145-
; CHECK-NEXT: ret float [[R1]]
134+
; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]
135+
; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.maxnum.f32(float [[TMP1]], float 1.000000e+00)
136+
; CHECK-NEXT: ret float [[TMP2]]
146137
;
147138
%inner_cmp = fcmp fast ult float %x, 255.0
148139
%inner_sel = select i1 %inner_cmp, float %x, float 255.0
@@ -157,9 +148,9 @@ define float @clamp_test_1(float %x) {
157148
define float @clamp_negative_wrong_const(float %x) {
158149
; CHECK-LABEL: define {{[^@]+}}@clamp_negative_wrong_const(
159150
; CHECK-NEXT: [[INNER_CMP_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
160-
; CHECK-NEXT: [[INNER_SEL:%.*]] = select i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]
151+
; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]
161152
; CHECK-NEXT: [[OUTER_CMP:%.*]] = fcmp fast ugt float [[X]], 5.120000e+02
162-
; CHECK-NEXT: [[R:%.*]] = select i1 [[OUTER_CMP]], float [[INNER_SEL]], float 5.120000e+02
153+
; CHECK-NEXT: [[R:%.*]] = select i1 [[OUTER_CMP]], float [[TMP1]], float 5.120000e+02
163154
; CHECK-NEXT: ret float [[R]]
164155
;
165156
%inner_cmp = fcmp fast ult float %x, 255.0
@@ -173,9 +164,9 @@ define float @clamp_negative_wrong_const(float %x) {
173164
define float @clamp_negative_same_op(float %x) {
174165
; CHECK-LABEL: define {{[^@]+}}@clamp_negative_same_op(
175166
; CHECK-NEXT: [[INNER_CMP_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
176-
; CHECK-NEXT: [[INNER_SEL:%.*]] = select i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]
167+
; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]
177168
; CHECK-NEXT: [[OUTER_CMP:%.*]] = fcmp fast ult float [[X]], 1.000000e+00
178-
; CHECK-NEXT: [[R:%.*]] = select i1 [[OUTER_CMP]], float [[INNER_SEL]], float 1.000000e+00
169+
; CHECK-NEXT: [[R:%.*]] = select i1 [[OUTER_CMP]], float [[TMP1]], float 1.000000e+00
179170
; CHECK-NEXT: ret float [[R]]
180171
;
181172
%inner_cmp = fcmp fast ult float %x, 255.0

llvm/test/Transforms/InstCombine/minmax-fold.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,11 +922,11 @@ define i32 @common_factor_umax_extra_use_both(i32 %a, i32 %b, i32 %c) {
922922
define float @not_min_of_min(i8 %i, float %x) {
923923
; CHECK-LABEL: define {{[^@]+}}@not_min_of_min(
924924
; CHECK-NEXT: [[CMP1_INV:%.*]] = fcmp fast oge float [[X:%.*]], 1.000000e+00
925-
; CHECK-NEXT: [[MIN1:%.*]] = select i1 [[CMP1_INV]], float 1.000000e+00, float [[X]]
925+
; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[CMP1_INV]], float 1.000000e+00, float [[X]]
926926
; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp fast oge float [[X]], 2.000000e+00
927-
; CHECK-NEXT: [[MIN2:%.*]] = select i1 [[CMP2_INV]], float 2.000000e+00, float [[X]]
927+
; CHECK-NEXT: [[TMP2:%.*]] = select fast i1 [[CMP2_INV]], float 2.000000e+00, float [[X]]
928928
; CHECK-NEXT: [[CMP3:%.*]] = icmp ult i8 [[I:%.*]], 16
929-
; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP3]], float [[MIN1]], float [[MIN2]]
929+
; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP3]], float [[TMP1]], float [[TMP2]]
930930
; CHECK-NEXT: ret float [[R]]
931931
;
932932
%cmp1 = fcmp fast ult float %x, 1.0

llvm/test/Transforms/InstCombine/minmax-fp.ll

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ define i8 @t9(float %a) {
149149
define i8 @t11(float %a, float %b) {
150150
; CHECK-LABEL: define {{[^@]+}}@t11(
151151
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp fast oge float [[B:%.*]], [[A:%.*]]
152-
; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[DOTINV]], float [[A]], float [[B]]
153-
; CHECK-NEXT: [[TMP1:%.*]] = fptosi float [[DOTV]] to i8
154-
; CHECK-NEXT: ret i8 [[TMP1]]
152+
; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[DOTINV]], float [[A]], float [[B]]
153+
; CHECK-NEXT: [[TMP2:%.*]] = fptosi float [[TMP1]] to i8
154+
; CHECK-NEXT: ret i8 [[TMP2]]
155155
;
156156
%1 = fcmp fast ult float %b, %a
157157
%2 = fptosi float %a to i8
@@ -164,9 +164,9 @@ define i8 @t11(float %a, float %b) {
164164
define i8 @t12(float %a, float %b) {
165165
; CHECK-LABEL: define {{[^@]+}}@t12(
166166
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp nnan oge float [[B:%.*]], [[A:%.*]]
167-
; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[DOTINV]], float [[A]], float [[B]]
168-
; CHECK-NEXT: [[TMP1:%.*]] = fptosi float [[DOTV]] to i8
169-
; CHECK-NEXT: ret i8 [[TMP1]]
167+
; CHECK-NEXT: [[TMP1:%.*]] = select nnan i1 [[DOTINV]], float [[A]], float [[B]]
168+
; CHECK-NEXT: [[TMP2:%.*]] = fptosi float [[TMP1]] to i8
169+
; CHECK-NEXT: ret i8 [[TMP2]]
170170
;
171171
%1 = fcmp nnan ult float %b, %a
172172
%2 = fptosi float %a to i8
@@ -219,7 +219,7 @@ define i8 @t14_commute(float %a) {
219219
define i8 @t15(float %a) {
220220
; CHECK-LABEL: define {{[^@]+}}@t15(
221221
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp nsz oge float [[A:%.*]], 0.000000e+00
222-
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[DOTINV]], float 0.000000e+00, float [[A]]
222+
; CHECK-NEXT: [[TMP1:%.*]] = select nsz i1 [[DOTINV]], float 0.000000e+00, float [[A]]
223223
; CHECK-NEXT: [[TMP2:%.*]] = fptosi float [[TMP1]] to i8
224224
; CHECK-NEXT: ret i8 [[TMP2]]
225225
;
@@ -272,8 +272,8 @@ define float @fneg_fmax(float %x, float %y) {
272272
define <2 x float> @fsub_fmax(<2 x float> %x, <2 x float> %y) {
273273
; CHECK-LABEL: define {{[^@]+}}@fsub_fmax(
274274
; CHECK-NEXT: [[COND_INV:%.*]] = fcmp nnan nsz ogt <2 x float> [[X:%.*]], [[Y:%.*]]
275-
; CHECK-NEXT: [[MAX_V:%.*]] = select <2 x i1> [[COND_INV]], <2 x float> [[Y]], <2 x float> [[X]]
276-
; CHECK-NEXT: [[MAX:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[MAX_V]]
275+
; CHECK-NEXT: [[TMP1:%.*]] = select nnan nsz <2 x i1> [[COND_INV]], <2 x float> [[Y]], <2 x float> [[X]]
276+
; CHECK-NEXT: [[MAX:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
277277
; CHECK-NEXT: ret <2 x float> [[MAX]]
278278
;
279279
%n1 = fsub <2 x float> <float -0.0, float -0.0>, %x
@@ -300,8 +300,8 @@ define <2 x double> @fsub_fmin(<2 x double> %x, <2 x double> %y) {
300300
define double @fneg_fmin(double %x, double %y) {
301301
; CHECK-LABEL: define {{[^@]+}}@fneg_fmin(
302302
; CHECK-NEXT: [[COND_INV:%.*]] = fcmp nnan nsz olt double [[X:%.*]], [[Y:%.*]]
303-
; CHECK-NEXT: [[MAX_V:%.*]] = select i1 [[COND_INV]], double [[Y]], double [[X]]
304-
; CHECK-NEXT: [[MAX:%.*]] = fneg double [[MAX_V]]
303+
; CHECK-NEXT: [[TMP1:%.*]] = select nnan nsz i1 [[COND_INV]], double [[Y]], double [[X]]
304+
; CHECK-NEXT: [[MAX:%.*]] = fneg double [[TMP1]]
305305
; CHECK-NEXT: ret double [[MAX]]
306306
;
307307
%n1 = fneg double %x

llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
define float @select_max_ugt(float %a, float %b) {
55
; CHECK-LABEL: define {{[^@]+}}@select_max_ugt(
66
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp arcp ole float [[A:%.*]], [[B:%.*]]
7-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
8-
; CHECK-NEXT: ret float [[SEL]]
7+
; CHECK-NEXT: [[TMP1:%.*]] = select arcp i1 [[CMP_INV]], float [[B]], float [[A]]
8+
; CHECK-NEXT: ret float [[TMP1]]
99
;
1010
%cmp = fcmp arcp ugt float %a, %b
1111
%sel = select arcp i1 %cmp, float %a, float %b
@@ -15,8 +15,8 @@ define float @select_max_ugt(float %a, float %b) {
1515
define float @select_max_uge(float %a, float %b) {
1616
; CHECK-LABEL: define {{[^@]+}}@select_max_uge(
1717
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp nnan olt float [[A:%.*]], [[B:%.*]]
18-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
19-
; CHECK-NEXT: ret float [[SEL]]
18+
; CHECK-NEXT: [[TMP1:%.*]] = select nnan i1 [[CMP_INV]], float [[B]], float [[A]]
19+
; CHECK-NEXT: ret float [[TMP1]]
2020
;
2121
%cmp = fcmp nnan uge float %a, %b
2222
%sel = select ninf i1 %cmp, float %a, float %b
@@ -25,9 +25,8 @@ define float @select_max_uge(float %a, float %b) {
2525

2626
define float @select_min_ugt(float %a, float %b) {
2727
; CHECK-LABEL: define {{[^@]+}}@select_min_ugt(
28-
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp fast ole float [[A:%.*]], [[B:%.*]]
29-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[A]], float [[B]]
30-
; CHECK-NEXT: ret float [[SEL]]
28+
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.minnum.f32(float [[A:%.*]], float [[B:%.*]])
29+
; CHECK-NEXT: ret float [[TMP1]]
3130
;
3231
%cmp = fcmp fast ugt float %a, %b
3332
%sel = select reassoc i1 %cmp, float %b, float %a
@@ -37,8 +36,8 @@ define float @select_min_ugt(float %a, float %b) {
3736
define float @select_min_uge(float %a, float %b) {
3837
; CHECK-LABEL: define {{[^@]+}}@select_min_uge(
3938
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp nsz olt float [[A:%.*]], [[B:%.*]]
40-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[A]], float [[B]]
41-
; CHECK-NEXT: ret float [[SEL]]
39+
; CHECK-NEXT: [[TMP1:%.*]] = select nsz i1 [[CMP_INV]], float [[A]], float [[B]]
40+
; CHECK-NEXT: ret float [[TMP1]]
4241
;
4342
%cmp = fcmp nsz uge float %a, %b
4443
%sel = select fast i1 %cmp, float %b, float %a
@@ -48,8 +47,8 @@ define float @select_min_uge(float %a, float %b) {
4847
define float @select_max_ult(float %a, float %b) {
4948
; CHECK-LABEL: define {{[^@]+}}@select_max_ult(
5049
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp arcp oge float [[A:%.*]], [[B:%.*]]
51-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[A]], float [[B]]
52-
; CHECK-NEXT: ret float [[SEL]]
50+
; CHECK-NEXT: [[TMP1:%.*]] = select arcp i1 [[CMP_INV]], float [[A]], float [[B]]
51+
; CHECK-NEXT: ret float [[TMP1]]
5352
;
5453
%cmp = fcmp arcp ult float %a, %b
5554
%sel = select ninf nnan i1 %cmp, float %b, float %a
@@ -58,9 +57,8 @@ define float @select_max_ult(float %a, float %b) {
5857

5958
define float @select_max_ule(float %a, float %b) {
6059
; CHECK-LABEL: define {{[^@]+}}@select_max_ule(
61-
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp fast ogt float [[A:%.*]], [[B:%.*]]
62-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[A]], float [[B]]
63-
; CHECK-NEXT: ret float [[SEL]]
60+
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.maxnum.f32(float [[A:%.*]], float [[B:%.*]])
61+
; CHECK-NEXT: ret float [[TMP1]]
6462
;
6563
%cmp = fcmp fast ule float %a, %b
6664
%sel = select nsz i1 %cmp, float %b, float %a
@@ -70,8 +68,8 @@ define float @select_max_ule(float %a, float %b) {
7068
define float @select_min_ult(float %a, float %b) {
7169
; CHECK-LABEL: define {{[^@]+}}@select_min_ult(
7270
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp nsz oge float [[A:%.*]], [[B:%.*]]
73-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
74-
; CHECK-NEXT: ret float [[SEL]]
71+
; CHECK-NEXT: [[TMP1:%.*]] = select nsz i1 [[CMP_INV]], float [[B]], float [[A]]
72+
; CHECK-NEXT: ret float [[TMP1]]
7573
;
7674
%cmp = fcmp nsz ult float %a, %b
7775
%sel = select fast i1 %cmp, float %a, float %b
@@ -81,8 +79,8 @@ define float @select_min_ult(float %a, float %b) {
8179
define float @select_min_ule(float %a, float %b) {
8280
; CHECK-LABEL: define {{[^@]+}}@select_min_ule(
8381
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp arcp ogt float [[A:%.*]], [[B:%.*]]
84-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
85-
; CHECK-NEXT: ret float [[SEL]]
82+
; CHECK-NEXT: [[TMP1:%.*]] = select arcp i1 [[CMP_INV]], float [[B]], float [[A]]
83+
; CHECK-NEXT: ret float [[TMP1]]
8684
;
8785
%cmp = fcmp arcp ule float %a, %b
8886
%sel = select ninf i1 %cmp, float %a, float %b
@@ -92,8 +90,8 @@ define float @select_min_ule(float %a, float %b) {
9290
define float @select_fcmp_une(float %a, float %b) {
9391
; CHECK-LABEL: define {{[^@]+}}@select_fcmp_une(
9492
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp reassoc oeq float [[A:%.*]], [[B:%.*]]
95-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
96-
; CHECK-NEXT: ret float [[SEL]]
93+
; CHECK-NEXT: [[TMP1:%.*]] = select reassoc i1 [[CMP_INV]], float [[B]], float [[A]]
94+
; CHECK-NEXT: ret float [[TMP1]]
9795
;
9896
%cmp = fcmp reassoc une float %a, %b
9997
%sel = select nnan i1 %cmp, float %a, float %b
@@ -103,8 +101,8 @@ define float @select_fcmp_une(float %a, float %b) {
103101
define float @select_fcmp_ueq(float %a, float %b) {
104102
; CHECK-LABEL: define {{[^@]+}}@select_fcmp_ueq(
105103
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp reassoc one float [[A:%.*]], [[B:%.*]]
106-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
107-
; CHECK-NEXT: ret float [[SEL]]
104+
; CHECK-NEXT: [[TMP1:%.*]] = select reassoc i1 [[CMP_INV]], float [[B]], float [[A]]
105+
; CHECK-NEXT: ret float [[TMP1]]
108106
;
109107
%cmp = fcmp reassoc ueq float %a, %b
110108
%sel = select arcp nnan i1 %cmp, float %a, float %b

0 commit comments

Comments
 (0)