Skip to content

Commit bc8d856

Browse files
committed
[NVPTX] Tighten up legal v2i16 ops a bit
TargetLoweringBase makes almost all ops legal by default, so make ones that Expand explicit and remove redundant legal settings.
1 parent 491a1cd commit bc8d856

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,6 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
467467
addRegisterClass(MVT::v2bf16, &NVPTX::Int32RegsRegClass);
468468

469469
// Conversion to/from FP16/FP16x2 is always legal.
470-
setOperationAction(ISD::SINT_TO_FP, MVT::f16, Legal);
471-
setOperationAction(ISD::FP_TO_SINT, MVT::f16, Legal);
472470
setOperationAction(ISD::BUILD_VECTOR, MVT::v2f16, Custom);
473471
setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2f16, Custom);
474472
setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v2f16, Expand);
@@ -478,8 +476,6 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
478476
setFP16OperationAction(ISD::SETCC, MVT::v2f16, Legal, Expand);
479477

480478
// Conversion to/from BFP16/BFP16x2 is always legal.
481-
setOperationAction(ISD::SINT_TO_FP, MVT::bf16, Legal);
482-
setOperationAction(ISD::FP_TO_SINT, MVT::bf16, Legal);
483479
setOperationAction(ISD::BUILD_VECTOR, MVT::v2bf16, Custom);
484480
setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2bf16, Custom);
485481
setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v2bf16, Expand);
@@ -644,6 +640,13 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
644640
setI16x2OperationAction(ISD::SREM, MVT::v2i16, Legal, Custom);
645641
setI16x2OperationAction(ISD::UREM, MVT::v2i16, Legal, Custom);
646642

643+
// Other arithmetic and logic ops are unsupported.
644+
setOperationAction({ISD::AND, ISD::OR, ISD::XOR, ISD::SDIV, ISD::UDIV,
645+
ISD::SRA, ISD::SRL, ISD::MULHS, ISD::MULHU,
646+
ISD::FP_TO_SINT, ISD::FP_TO_UINT, ISD::SINT_TO_FP,
647+
ISD::UINT_TO_FP},
648+
MVT::v2i16, Expand);
649+
647650
setOperationAction(ISD::ADDC, MVT::i32, Legal);
648651
setOperationAction(ISD::ADDE, MVT::i32, Legal);
649652
setOperationAction(ISD::SUBC, MVT::i32, Legal);

llvm/test/CodeGen/NVPTX/f16x2-instructions.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,5 +1468,23 @@ define <2 x half> @test_insertelement(<2 x half> %a, half %x) #0 {
14681468
ret <2 x half> %i
14691469
}
14701470

1471+
; CHECK-LABEL: test_sitofp_2xi16_to_2xhalf(
1472+
; CHECK: cvt.rn.f16.s16
1473+
; CHECK: cvt.rn.f16.s16
1474+
; CHECK: ret;
1475+
define <2 x half> @test_sitofp_2xi16_to_2xhalf(<2 x i16> %a) #0 {
1476+
%r = sitofp <2 x i16> %a to <2 x half>
1477+
ret <2 x half> %r
1478+
}
1479+
1480+
; CHECK-LABEL: test_uitofp_2xi16_to_2xhalf(
1481+
; CHECK: cvt.rn.f16.u16
1482+
; CHECK: cvt.rn.f16.u16
1483+
; CHECK: ret;
1484+
define <2 x half> @test_uitofp_2xi16_to_2xhalf(<2 x i16> %a) #0 {
1485+
%r = uitofp <2 x i16> %a to <2 x half>
1486+
ret <2 x half> %r
1487+
}
1488+
14711489
attributes #0 = { nounwind }
14721490
attributes #1 = { "unsafe-fp-math" = "true" }

llvm/test/CodeGen/NVPTX/i16x2-instructions.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,4 +534,22 @@ define <2 x i16> @test_insertelement(<2 x i16> %a, i16 %x) #0 {
534534
ret <2 x i16> %i
535535
}
536536

537+
; COMMON-LABEL: test_fptosi_2xhalf_to_2xi16(
538+
; COMMON: cvt.rzi.s16.f16
539+
; COMMON: cvt.rzi.s16.f16
540+
; COMMON: ret;
541+
define <2 x i16> @test_fptosi_2xhalf_to_2xi16(<2 x half> %a) #0 {
542+
%r = fptosi <2 x half> %a to <2 x i16>
543+
ret <2 x i16> %r
544+
}
545+
546+
; COMMON-LABEL: test_fptoui_2xhalf_to_2xi16(
547+
; COMMON: cvt.rzi.u16.f16
548+
; COMMON: cvt.rzi.u16.f16
549+
; COMMON: ret;
550+
define <2 x i16> @test_fptoui_2xhalf_to_2xi16(<2 x half> %a) #0 {
551+
%r = fptoui <2 x half> %a to <2 x i16>
552+
ret <2 x i16> %r
553+
}
554+
537555
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)