Skip to content

Commit 097a95f

Browse files
Ting WangTing Wang
authored andcommitted
[PowerPC] Add custom lowering for SELECT_CC fp128 using xsmaxcqp
Power ISA 3.1 adds xsmaxcqp/xsmincqp for quad-precision type-c max/min selection, and this opens the opportunity to improve instruction selection on: llvm.maxnum.f128, llvm.minnum.f128, and select_cc ordered gt/lt and (don't care) gt/lt. Reviewed By: nemanjai, shchenz, amyk Differential Revision: https://reviews.llvm.org/D117006
1 parent f3481f4 commit 097a95f

File tree

5 files changed

+90
-12
lines changed

5 files changed

+90
-12
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,10 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
12831283
setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i32, Legal);
12841284
setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i64, Legal);
12851285
}
1286+
1287+
if (Subtarget.hasP10Vector()) {
1288+
setOperationAction(ISD::SELECT_CC, MVT::f128, Custom);
1289+
}
12861290
}
12871291

12881292
if (Subtarget.pairedVectorMemops()) {
@@ -1605,8 +1609,8 @@ const char *PPCTargetLowering::getTargetNodeName(unsigned Opcode) const {
16051609
switch ((PPCISD::NodeType)Opcode) {
16061610
case PPCISD::FIRST_NUMBER: break;
16071611
case PPCISD::FSEL: return "PPCISD::FSEL";
1608-
case PPCISD::XSMAXCDP: return "PPCISD::XSMAXCDP";
1609-
case PPCISD::XSMINCDP: return "PPCISD::XSMINCDP";
1612+
case PPCISD::XSMAXC: return "PPCISD::XSMAXC";
1613+
case PPCISD::XSMINC: return "PPCISD::XSMINC";
16101614
case PPCISD::FCFID: return "PPCISD::FCFID";
16111615
case PPCISD::FCFIDU: return "PPCISD::FCFIDU";
16121616
case PPCISD::FCFIDS: return "PPCISD::FCFIDS";
@@ -7898,18 +7902,18 @@ SDValue PPCTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const {
78987902

78997903
SDNodeFlags Flags = Op.getNode()->getFlags();
79007904

7901-
// We have xsmaxcdp/xsmincdp which are OK to emit even in the
7905+
// We have xsmaxc[dq]p/xsminc[dq]p which are OK to emit even in the
79027906
// presence of infinities.
79037907
if (Subtarget.hasP9Vector() && LHS == TV && RHS == FV) {
79047908
switch (CC) {
79057909
default:
79067910
break;
79077911
case ISD::SETOGT:
79087912
case ISD::SETGT:
7909-
return DAG.getNode(PPCISD::XSMAXCDP, dl, Op.getValueType(), LHS, RHS);
7913+
return DAG.getNode(PPCISD::XSMAXC, dl, Op.getValueType(), LHS, RHS);
79107914
case ISD::SETOLT:
79117915
case ISD::SETLT:
7912-
return DAG.getNode(PPCISD::XSMINCDP, dl, Op.getValueType(), LHS, RHS);
7916+
return DAG.getNode(PPCISD::XSMINC, dl, Op.getValueType(), LHS, RHS);
79137917
}
79147918
}
79157919

llvm/lib/Target/PowerPC/PPCISelLowering.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ namespace llvm {
5151
///
5252
FSEL,
5353

54-
/// XSMAXCDP, XSMINCDP - C-type min/max instructions.
55-
XSMAXCDP,
56-
XSMINCDP,
54+
/// XSMAXC[DQ]P, XSMINC[DQ]P - C-type min/max instructions.
55+
XSMAXC,
56+
XSMINC,
5757

5858
/// FCFID - The FCFID instruction, taking an f64 operand and producing
5959
/// and f64 value containing the FP representation of the integer that

llvm/lib/Target/PowerPC/PPCInstrInfo.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ def PPCfsel : SDNode<"PPCISD::FSEL",
198198
// Type constraint for fsel.
199199
SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>,
200200
SDTCisFP<0>, SDTCisVT<1, f64>]>, []>;
201-
def PPCxsmaxc : SDNode<"PPCISD::XSMAXCDP", SDT_PPCFPMinMax, []>;
202-
def PPCxsminc : SDNode<"PPCISD::XSMINCDP", SDT_PPCFPMinMax, []>;
201+
def PPCxsmaxc : SDNode<"PPCISD::XSMAXC", SDT_PPCFPMinMax, []>;
202+
def PPCxsminc : SDNode<"PPCISD::XSMINC", SDT_PPCFPMinMax, []>;
203203
def PPChi : SDNode<"PPCISD::Hi", SDTIntBinOp, []>;
204204
def PPClo : SDNode<"PPCISD::Lo", SDTIntBinOp, []>;
205205
def PPCtoc_entry: SDNode<"PPCISD::TOC_ENTRY", SDTIntBinOp,

llvm/lib/Target/PowerPC/PPCInstrPrefix.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,8 +2398,10 @@ let Predicates = [IsISA3_1] in {
23982398
let Predicates = [IsISA3_1, HasVSX] in {
23992399
def XVCVSPBF16 : XX2_XT6_XO5_XB6<60, 17, 475, "xvcvspbf16", vsrc, []>;
24002400
def XVCVBF16SPN : XX2_XT6_XO5_XB6<60, 16, 475, "xvcvbf16spn", vsrc, []>;
2401-
def XSMAXCQP : X_VT5_VA5_VB5<63, 676, "xsmaxcqp", []>;
2402-
def XSMINCQP : X_VT5_VA5_VB5<63, 740, "xsmincqp", []>;
2401+
def XSMAXCQP : X_VT5_VA5_VB5<63, 676, "xsmaxcqp",
2402+
[(set f128:$vT, (PPCxsmaxc f128:$vA, f128:$vB))]>;
2403+
def XSMINCQP : X_VT5_VA5_VB5<63, 740, "xsmincqp",
2404+
[(set f128:$vT, (PPCxsminc f128:$vA, f128:$vB))]>;
24032405
}
24042406

24052407
// Multiclass defining patterns for Set Boolean Extension Reverse Instructions.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mcpu=pwr10 -ppc-asm-full-reg-names --enable-unsafe-fp-math \
3+
; RUN: -verify-machineinstrs --enable-no-signed-zeros-fp-math \
4+
; RUN: --enable-no-nans-fp-math \
5+
; RUN: -mtriple=powerpc64le-unknown-unknown < %s | FileCheck %s
6+
; RUN: llc -mcpu=pwr10 -ppc-asm-full-reg-names -verify-machineinstrs \
7+
; RUN: -mtriple=powerpc64le-unknown-unknown < %s | FileCheck %s
8+
define dso_local fp128 @testqmax(fp128 %a, fp128 %b) local_unnamed_addr {
9+
; CHECK-LABEL: testqmax:
10+
; CHECK: # %bb.0: # %entry
11+
; CHECK-NEXT: xsmaxcqp v2, v2, v3
12+
; CHECK-NEXT: blr
13+
entry:
14+
%cmp = fcmp ogt fp128 %a, %b
15+
%cond = select i1 %cmp, fp128 %a, fp128 %b
16+
ret fp128 %cond
17+
}
18+
19+
define dso_local fp128 @testqmin(fp128 %a, fp128 %b) local_unnamed_addr {
20+
; CHECK-LABEL: testqmin:
21+
; CHECK: # %bb.0: # %entry
22+
; CHECK-NEXT: xsmincqp v2, v2, v3
23+
; CHECK-NEXT: blr
24+
entry:
25+
%cmp = fcmp olt fp128 %a, %b
26+
%cond = select i1 %cmp, fp128 %a, fp128 %b
27+
ret fp128 %cond
28+
}
29+
30+
define dso_local fp128 @testqmax_fast(fp128 %a, fp128 %b) local_unnamed_addr {
31+
; CHECK-LABEL: testqmax_fast:
32+
; CHECK: # %bb.0: # %entry
33+
; CHECK-NEXT: xsmaxcqp v2, v2, v3
34+
; CHECK-NEXT: blr
35+
entry:
36+
%cmp = fcmp nnan ninf ogt fp128 %a, %b
37+
%cond = select i1 %cmp, fp128 %a, fp128 %b
38+
ret fp128 %cond
39+
}
40+
41+
define dso_local fp128 @testqmin_fast(fp128 %a, fp128 %b) local_unnamed_addr {
42+
; CHECK-LABEL: testqmin_fast:
43+
; CHECK: # %bb.0: # %entry
44+
; CHECK-NEXT: xsmincqp v2, v2, v3
45+
; CHECK-NEXT: blr
46+
entry:
47+
%cmp = fcmp nnan ninf olt fp128 %a, %b
48+
%cond = select i1 %cmp, fp128 %a, fp128 %b
49+
ret fp128 %cond
50+
}
51+
52+
declare fp128 @llvm.maxnum.f128(fp128, fp128)
53+
define dso_local fp128 @testq_intrinsic_maxnum(fp128 %a, fp128 %b) local_unnamed_addr {
54+
; CHECK-LABEL: testq_intrinsic_maxnum:
55+
; CHECK: # %bb.0: # %entry
56+
; CHECK-NEXT: xsmaxcqp v2, v2, v3
57+
; CHECK-NEXT: blr
58+
entry:
59+
%0 = tail call fast fp128 @llvm.maxnum.f128(fp128 %a, fp128 %b)
60+
ret fp128 %0
61+
}
62+
63+
declare fp128 @llvm.minnum.f128(fp128, fp128)
64+
define dso_local fp128 @testq_intrinsic_minnum(fp128 %a, fp128 %b) local_unnamed_addr {
65+
; CHECK-LABEL: testq_intrinsic_minnum:
66+
; CHECK: # %bb.0: # %entry
67+
; CHECK-NEXT: xsmincqp v2, v2, v3
68+
; CHECK-NEXT: blr
69+
entry:
70+
%0 = tail call fast fp128 @llvm.minnum.f128(fp128 %a, fp128 %b)
71+
ret fp128 %0
72+
}

0 commit comments

Comments
 (0)