Skip to content

Commit e12cf62

Browse files
committed
[ARM] Disable strict node mutation and use correct lowering for several strict ops
1 parent 4a6451a commit e12cf62

File tree

4 files changed

+1543
-36
lines changed

4 files changed

+1543
-36
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -546,16 +546,24 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
546546
for (auto Op : {ISD::STRICT_FADD, ISD::STRICT_FSUB, ISD::STRICT_FMUL,
547547
ISD::STRICT_FDIV, ISD::STRICT_FMA, ISD::STRICT_FSQRT})
548548
setOperationAction(Op, MVT::f64, Legal);
549+
550+
setOperationAction(ISD::STRICT_FP_ROUND, MVT::f32, Legal);
549551
}
550552
}
551553

552554
if (Subtarget->hasFullFP16()) {
555+
for (auto Op : {ISD::STRICT_FADD, ISD::STRICT_FSUB, ISD::STRICT_FMUL,
556+
ISD::STRICT_FDIV, ISD::STRICT_FMA, ISD::STRICT_FSQRT})
557+
setOperationAction(Op, MVT::f16, Legal);
558+
553559
addRegisterClass(MVT::f16, &ARM::HPRRegClass);
554560
setOperationAction(ISD::BITCAST, MVT::i16, Custom);
555561
setOperationAction(ISD::BITCAST, MVT::f16, Custom);
556562

557563
setOperationAction(ISD::FMINNUM, MVT::f16, Legal);
558564
setOperationAction(ISD::FMAXNUM, MVT::f16, Legal);
565+
setOperationAction(ISD::STRICT_FMINNUM, MVT::f16, Legal);
566+
setOperationAction(ISD::STRICT_FMAXNUM, MVT::f16, Legal);
559567
}
560568

561569
if (Subtarget->hasBF16()) {
@@ -865,25 +873,31 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
865873
setOperationAction(ISD::FP_TO_SINT, MVT::f64, Custom);
866874
setOperationAction(ISD::FP_TO_UINT, MVT::f64, Custom);
867875
setOperationAction(ISD::FP_ROUND, MVT::f32, Custom);
868-
setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i32, Custom);
869-
setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i32, Custom);
870876
setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::f64, Custom);
871877
setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::f64, Custom);
872878
setOperationAction(ISD::STRICT_FP_ROUND, MVT::f32, Custom);
873879
}
874880

881+
setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i32, Custom);
882+
setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i32, Custom);
883+
875884
if (!Subtarget->hasFP64() || !Subtarget->hasFPARMv8Base()) {
876885
setOperationAction(ISD::FP_EXTEND, MVT::f64, Custom);
877886
setOperationAction(ISD::STRICT_FP_EXTEND, MVT::f64, Custom);
878887
if (Subtarget->hasFullFP16()) {
879888
setOperationAction(ISD::FP_ROUND, MVT::f16, Custom);
880889
setOperationAction(ISD::STRICT_FP_ROUND, MVT::f16, Custom);
881890
}
891+
} else {
892+
setOperationAction(ISD::STRICT_FP_EXTEND, MVT::f64, Legal);
882893
}
883894

884895
if (!Subtarget->hasFP16()) {
885896
setOperationAction(ISD::FP_EXTEND, MVT::f32, Custom);
886897
setOperationAction(ISD::STRICT_FP_EXTEND, MVT::f32, Custom);
898+
} else {
899+
setOperationAction(ISD::STRICT_FP_EXTEND, MVT::f32, Legal);
900+
setOperationAction(ISD::STRICT_FP_ROUND, MVT::f16, Legal);
887901
}
888902

889903
computeRegisterProperties(Subtarget->getRegisterInfo());
@@ -1223,16 +1237,16 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
12231237
if (!Subtarget->hasFPARMv8Base() || !Subtarget->hasFP64()) {
12241238
setOperationAction(ISD::FP16_TO_FP, MVT::f64, Expand);
12251239
setOperationAction(ISD::FP_TO_FP16, MVT::f64, Expand);
1226-
setOperationAction(ISD::STRICT_FP16_TO_FP, MVT::f64, LibCall);
1227-
setOperationAction(ISD::STRICT_FP_TO_FP16, MVT::f64, LibCall);
1240+
setOperationAction(ISD::STRICT_FP16_TO_FP, MVT::f64, Expand);
1241+
setOperationAction(ISD::STRICT_FP_TO_FP16, MVT::f64, Expand);
12281242
}
12291243

12301244
// fp16 is a special v7 extension that adds f16 <-> f32 conversions.
12311245
if (!Subtarget->hasFP16()) {
12321246
setOperationAction(ISD::FP16_TO_FP, MVT::f32, Expand);
12331247
setOperationAction(ISD::FP_TO_FP16, MVT::f32, Expand);
1234-
setOperationAction(ISD::STRICT_FP16_TO_FP, MVT::f32, LibCall);
1235-
setOperationAction(ISD::STRICT_FP_TO_FP16, MVT::f32, LibCall);
1248+
setOperationAction(ISD::STRICT_FP16_TO_FP, MVT::f32, Expand);
1249+
setOperationAction(ISD::STRICT_FP_TO_FP16, MVT::f32, Expand);
12361250
}
12371251

12381252
// Strict floating-point comparisons need custom lowering.
@@ -1248,34 +1262,26 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
12481262
setOperationAction(ISD::FSINCOS, MVT::f32, Expand);
12491263

12501264
// FP-ARMv8 implements a lot of rounding-like FP operations.
1251-
if (Subtarget->hasFPARMv8Base()) {
1252-
setOperationAction(ISD::FFLOOR, MVT::f32, Legal);
1253-
setOperationAction(ISD::FCEIL, MVT::f32, Legal);
1254-
setOperationAction(ISD::FROUND, MVT::f32, Legal);
1255-
setOperationAction(ISD::FTRUNC, MVT::f32, Legal);
1256-
setOperationAction(ISD::FNEARBYINT, MVT::f32, Legal);
1257-
setOperationAction(ISD::FRINT, MVT::f32, Legal);
1258-
setOperationAction(ISD::FROUNDEVEN, MVT::f32, Legal);
1259-
setOperationAction(ISD::FMINNUM, MVT::f32, Legal);
1260-
setOperationAction(ISD::FMAXNUM, MVT::f32, Legal);
1265+
if (Subtarget->hasFPARMv8Base()) {
1266+
for (auto Op :
1267+
{ISD::FFLOOR, ISD::FCEIL, ISD::FROUND,
1268+
ISD::FTRUNC, ISD::FNEARBYINT, ISD::FRINT,
1269+
ISD::FROUNDEVEN, ISD::FMINNUM, ISD::FMAXNUM,
1270+
ISD::STRICT_FFLOOR, ISD::STRICT_FCEIL, ISD::STRICT_FROUND,
1271+
ISD::STRICT_FTRUNC, ISD::STRICT_FNEARBYINT, ISD::STRICT_FRINT,
1272+
ISD::STRICT_FROUNDEVEN, ISD::STRICT_FMINNUM, ISD::STRICT_FMAXNUM}) {
1273+
setOperationAction(Op, MVT::f32, Legal);
1274+
1275+
if (Subtarget->hasFP64())
1276+
setOperationAction(Op, MVT::f64, Legal);
1277+
}
1278+
12611279
if (Subtarget->hasNEON()) {
12621280
setOperationAction(ISD::FMINNUM, MVT::v2f32, Legal);
12631281
setOperationAction(ISD::FMAXNUM, MVT::v2f32, Legal);
12641282
setOperationAction(ISD::FMINNUM, MVT::v4f32, Legal);
12651283
setOperationAction(ISD::FMAXNUM, MVT::v4f32, Legal);
12661284
}
1267-
1268-
if (Subtarget->hasFP64()) {
1269-
setOperationAction(ISD::FFLOOR, MVT::f64, Legal);
1270-
setOperationAction(ISD::FCEIL, MVT::f64, Legal);
1271-
setOperationAction(ISD::FROUND, MVT::f64, Legal);
1272-
setOperationAction(ISD::FTRUNC, MVT::f64, Legal);
1273-
setOperationAction(ISD::FNEARBYINT, MVT::f64, Legal);
1274-
setOperationAction(ISD::FRINT, MVT::f64, Legal);
1275-
setOperationAction(ISD::FROUNDEVEN, MVT::f64, Legal);
1276-
setOperationAction(ISD::FMINNUM, MVT::f64, Legal);
1277-
setOperationAction(ISD::FMAXNUM, MVT::f64, Legal);
1278-
}
12791285
}
12801286

12811287
// FP16 often need to be promoted to call lib functions
@@ -1430,6 +1436,8 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
14301436
Align(1ULL << Subtarget->getPreferBranchLogAlignment()));
14311437

14321438
setMinFunctionAlignment(Subtarget->isThumb() ? Align(2) : Align(4));
1439+
1440+
IsStrictFPEnabled = true;
14331441
}
14341442

14351443
bool ARMTargetLowering::useSoftFloat() const {

llvm/lib/Target/ARM/ARMInstrVFP.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ def VCVTBHS: ASuI<0b11101, 0b11, 0b0010, 0b01, 0, (outs SPR:$Sd), (ins SPR:$Sm),
814814

815815
def : FP16Pat<(f32 (any_fpextend (f16 HPR:$Sm))),
816816
(VCVTBHS (COPY_TO_REGCLASS (f16 HPR:$Sm), SPR))>;
817-
def : FP16Pat<(f16_to_fp GPR:$a),
817+
def : FP16Pat<(any_f16_to_fp GPR:$a),
818818
(VCVTBHS (COPY_TO_REGCLASS GPR:$a, SPR))>;
819819

820820
let hasSideEffects = 0, mayRaiseFPException = 1, Uses = [FPSCR_RM] in
@@ -826,7 +826,7 @@ def VCVTBSH: ASuI<0b11101, 0b11, 0b0011, 0b01, 0, (outs SPR:$Sd), (ins SPR:$Sda,
826826

827827
def : FP16Pat<(f16 (any_fpround SPR:$Sm)),
828828
(COPY_TO_REGCLASS (VCVTBSH (IMPLICIT_DEF), SPR:$Sm), HPR)>;
829-
def : FP16Pat<(fp_to_f16 SPR:$a),
829+
def : FP16Pat<(any_fp_to_f16 SPR:$a),
830830
(i32 (COPY_TO_REGCLASS (VCVTBSH (IMPLICIT_DEF), SPR:$a), GPR))>;
831831
def : FP16Pat<(insertelt (v8f16 MQPR:$src1), (f16 (any_fpround (f32 SPR:$src2))), imm_even:$lane),
832832
(v8f16 (INSERT_SUBREG (v8f16 MQPR:$src1),
@@ -891,7 +891,7 @@ def VCVTBHD : ADuI<0b11101, 0b11, 0b0010, 0b01, 0,
891891
def : FullFP16Pat<(f64 (any_fpextend (f16 HPR:$Sm))),
892892
(VCVTBHD (COPY_TO_REGCLASS (f16 HPR:$Sm), SPR))>,
893893
Requires<[HasFPARMv8, HasDPVFP]>;
894-
def : FP16Pat<(f64 (f16_to_fp GPR:$a)),
894+
def : FP16Pat<(f64 (any_f16_to_fp GPR:$a)),
895895
(VCVTBHD (COPY_TO_REGCLASS GPR:$a, SPR))>,
896896
Requires<[HasFPARMv8, HasDPVFP]>;
897897

@@ -917,7 +917,7 @@ def VCVTBDH : ADuI<0b11101, 0b11, 0b0011, 0b01, 0,
917917
def : FullFP16Pat<(f16 (any_fpround DPR:$Dm)),
918918
(COPY_TO_REGCLASS (VCVTBDH (IMPLICIT_DEF), DPR:$Dm), HPR)>,
919919
Requires<[HasFPARMv8, HasDPVFP]>;
920-
def : FP16Pat<(fp_to_f16 (f64 DPR:$a)),
920+
def : FP16Pat<(any_fp_to_f16 (f64 DPR:$a)),
921921
(i32 (COPY_TO_REGCLASS (VCVTBDH (IMPLICIT_DEF), DPR:$a), GPR))>,
922922
Requires<[HasFPARMv8, HasDPVFP]>;
923923

0 commit comments

Comments
 (0)