Skip to content

Commit 682b443

Browse files
committed
PowerPC/VSX: Select FMINNUM and FMAXNUM
In LangRef, we claim that FMINNUM and FMAXNUM should follow the minNum and maxNum operators in IEEE754-2008. PowerPC/VSX does have these instructions XSMINDP and XSMAXDP.
1 parent ce1748f commit 682b443

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,10 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
777777
setOperationAction(ISD::FMAXNUM_IEEE, MVT::f32, Legal);
778778
setOperationAction(ISD::FMINNUM_IEEE, MVT::f64, Legal);
779779
setOperationAction(ISD::FMINNUM_IEEE, MVT::f32, Legal);
780+
setOperationAction(ISD::FMAXNUM, MVT::f64, Legal);
781+
setOperationAction(ISD::FMAXNUM, MVT::f32, Legal);
782+
setOperationAction(ISD::FMINNUM, MVT::f64, Legal);
783+
setOperationAction(ISD::FMINNUM, MVT::f32, Legal);
780784
}
781785

782786
if (Subtarget.hasAltivec()) {

llvm/lib/Target/PowerPC/PPCInstrVSX.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,8 @@ def : Pat<(f32 (fneg (fabs f32:$S))),
27312731
(COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
27322732

27332733
// f32 Min.
2734+
def : Pat<(f32 (fminnum f32:$A, f32:$B)),
2735+
(f32 FpMinMax.F32Min)>;
27342736
def : Pat<(f32 (fminnum_ieee f32:$A, f32:$B)),
27352737
(f32 FpMinMax.F32Min)>;
27362738
def : Pat<(f32 (fminnum_ieee (fcanonicalize f32:$A), f32:$B)),
@@ -2742,6 +2744,8 @@ def : Pat<(f32 (fminnum_ieee (fcanonicalize f32:$A), (fcanonicalize f32:$B))),
27422744
// F32 Max.
27432745
def : Pat<(f32 (fmaxnum_ieee f32:$A, f32:$B)),
27442746
(f32 FpMinMax.F32Max)>;
2747+
def : Pat<(f32 (fmaxnum f32:$A, f32:$B)),
2748+
(f32 FpMinMax.F32Max)>;
27452749
def : Pat<(f32 (fmaxnum_ieee (fcanonicalize f32:$A), f32:$B)),
27462750
(f32 FpMinMax.F32Max)>;
27472751
def : Pat<(f32 (fmaxnum_ieee f32:$A, (fcanonicalize f32:$B))),
@@ -2750,6 +2754,8 @@ def : Pat<(f32 (fmaxnum_ieee (fcanonicalize f32:$A), (fcanonicalize f32:$B))),
27502754
(f32 FpMinMax.F32Max)>;
27512755

27522756
// f64 Min.
2757+
def : Pat<(f64 (fminnum f64:$A, f64:$B)),
2758+
(f64 (XSMINDP $A, $B))>;
27532759
def : Pat<(f64 (fminnum_ieee f64:$A, f64:$B)),
27542760
(f64 (XSMINDP $A, $B))>;
27552761
def : Pat<(f64 (fminnum_ieee (fcanonicalize f64:$A), f64:$B)),
@@ -2759,6 +2765,8 @@ def : Pat<(f64 (fminnum_ieee f64:$A, (fcanonicalize f64:$B))),
27592765
def : Pat<(f64 (fminnum_ieee (fcanonicalize f64:$A), (fcanonicalize f64:$B))),
27602766
(f64 (XSMINDP $A, $B))>;
27612767
// f64 Max.
2768+
def : Pat<(f64 (fmaxnum f64:$A, f64:$B)),
2769+
(f64 (XSMAXDP $A, $B))>;
27622770
def : Pat<(f64 (fmaxnum_ieee f64:$A, f64:$B)),
27632771
(f64 (XSMAXDP $A, $B))>;
27642772
def : Pat<(f64 (fmaxnum_ieee (fcanonicalize f64:$A), f64:$B)),

llvm/test/CodeGen/PowerPC/scalar-min-max.ll

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,12 @@ define dso_local float @testfmax_fast(float %a, float %b) local_unnamed_addr {
117117
;
118118
; NO-FAST-P9-LABEL: testfmax_fast:
119119
; NO-FAST-P9: # %bb.0: # %entry
120-
; NO-FAST-P9-NEXT: xsmaxcdp f1, f1, f2
120+
; NO-FAST-P9-NEXT: xsmaxdp f1, f1, f2
121121
; NO-FAST-P9-NEXT: blr
122122
;
123123
; NO-FAST-P8-LABEL: testfmax_fast:
124124
; NO-FAST-P8: # %bb.0: # %entry
125-
; NO-FAST-P8-NEXT: xssubsp f0, f2, f1
126-
; NO-FAST-P8-NEXT: fsel f1, f0, f2, f1
125+
; NO-FAST-P8-NEXT: xsmaxdp f1, f1, f2
127126
; NO-FAST-P8-NEXT: blr
128127
entry:
129128
%cmp = fcmp nnan ninf ogt float %a, %b
@@ -138,13 +137,12 @@ define dso_local double @testdmax_fast(double %a, double %b) local_unnamed_addr
138137
;
139138
; NO-FAST-P9-LABEL: testdmax_fast:
140139
; NO-FAST-P9: # %bb.0: # %entry
141-
; NO-FAST-P9-NEXT: xsmaxcdp f1, f1, f2
140+
; NO-FAST-P9-NEXT: xsmaxdp f1, f1, f2
142141
; NO-FAST-P9-NEXT: blr
143142
;
144143
; NO-FAST-P8-LABEL: testdmax_fast:
145144
; NO-FAST-P8: # %bb.0: # %entry
146-
; NO-FAST-P8-NEXT: xssubdp f0, f2, f1
147-
; NO-FAST-P8-NEXT: fsel f1, f0, f2, f1
145+
; NO-FAST-P8-NEXT: xsmaxdp f1, f1, f2
148146
; NO-FAST-P8-NEXT: blr
149147
entry:
150148
%cmp = fcmp nnan ninf ogt double %a, %b
@@ -159,13 +157,12 @@ define dso_local float @testfmin_fast(float %a, float %b) local_unnamed_addr {
159157
;
160158
; NO-FAST-P9-LABEL: testfmin_fast:
161159
; NO-FAST-P9: # %bb.0: # %entry
162-
; NO-FAST-P9-NEXT: xsmincdp f1, f1, f2
160+
; NO-FAST-P9-NEXT: xsmindp f1, f1, f2
163161
; NO-FAST-P9-NEXT: blr
164162
;
165163
; NO-FAST-P8-LABEL: testfmin_fast:
166164
; NO-FAST-P8: # %bb.0: # %entry
167-
; NO-FAST-P8-NEXT: xssubsp f0, f1, f2
168-
; NO-FAST-P8-NEXT: fsel f1, f0, f2, f1
165+
; NO-FAST-P8-NEXT: xsmindp f1, f1, f2
169166
; NO-FAST-P8-NEXT: blr
170167
entry:
171168
%cmp = fcmp nnan ninf olt float %a, %b
@@ -180,13 +177,12 @@ define dso_local double @testdmin_fast(double %a, double %b) local_unnamed_addr
180177
;
181178
; NO-FAST-P9-LABEL: testdmin_fast:
182179
; NO-FAST-P9: # %bb.0: # %entry
183-
; NO-FAST-P9-NEXT: xsmincdp f1, f1, f2
180+
; NO-FAST-P9-NEXT: xsmindp f1, f1, f2
184181
; NO-FAST-P9-NEXT: blr
185182
;
186183
; NO-FAST-P8-LABEL: testdmin_fast:
187184
; NO-FAST-P8: # %bb.0: # %entry
188-
; NO-FAST-P8-NEXT: xssubdp f0, f1, f2
189-
; NO-FAST-P8-NEXT: fsel f1, f0, f2, f1
185+
; NO-FAST-P8-NEXT: xsmindp f1, f1, f2
190186
; NO-FAST-P8-NEXT: blr
191187
entry:
192188
%cmp = fcmp nnan ninf olt double %a, %b

0 commit comments

Comments
 (0)