Skip to content

Commit 76d1f5e

Browse files
jchlandaArtem-B
authored andcommitted
[NVPTX] Support float <-> 2 x half bitcasts
Make sure NVPTX backend can handle bitcasting between `float` and `<2 x half>` types. This was discovered through: #5969 I'm not suggesting that such bitcasts make much sense, but it feels like the compiler should not hard crash on them. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D124171
1 parent 993054c commit 76d1f5e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

llvm/lib/Target/NVPTX/NVPTXInstrInfo.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,6 +2658,8 @@ def BITCONVERT_64_I2F : F_BITCONVERT<"64", Int64Regs, Float64Regs>;
26582658
def BITCONVERT_64_F2I : F_BITCONVERT<"64", Float64Regs, Int64Regs>;
26592659
def BITCONVERT_32_I2F16x2 : F_BITCONVERT<"32", Int32Regs, Float16x2Regs>;
26602660
def BITCONVERT_32_F16x22I : F_BITCONVERT<"32", Float16x2Regs, Int32Regs>;
2661+
def BITCONVERT_32_F2F16x2 : F_BITCONVERT<"32", Float32Regs, Float16x2Regs>;
2662+
def BITCONVERT_32_F16x22F : F_BITCONVERT<"32", Float16x2Regs, Float32Regs>;
26612663

26622664
// NOTE: pred->fp are currently sub-optimal due to an issue in TableGen where
26632665
// we cannot specify floating-point literals in isel patterns. Therefore, we

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,25 @@ define <2 x half> @test_bitcast_2xi16_to_2xhalf(<2 x i16> %a) #0 {
10021002
ret <2 x half> %r
10031003
}
10041004

1005+
; CHECK-LABEL: test_bitcast_float_to_2xhalf(
1006+
; CHECK: ld.param.f32 [[AF1:%f[0-9]+]], [test_bitcast_float_to_2xhalf_param_0];
1007+
; CHECK: mov.b32 [[R:%hh[0-9]+]], [[AF1]];
1008+
; CHECK: st.param.b32 [func_retval0+0], [[R]];
1009+
; CHECK: ret;
1010+
define <2 x half> @test_bitcast_float_to_2xhalf(float %a) #0 {
1011+
%r = bitcast float %a to <2 x half>
1012+
ret <2 x half> %r
1013+
}
1014+
1015+
; CHECK-LABEL: test_bitcast_2xhalf_to_float(
1016+
; CHECK: ld.param.u32 [[R:%r[0-9]+]], [test_bitcast_2xhalf_to_float_param_0];
1017+
; CHECK: mov.b32 [[AF1:%f[0-9]+]], [[R]];
1018+
; CHECK: st.param.f32 [func_retval0+0], [[AF1]];
1019+
; CHECK: ret;
1020+
define float @test_bitcast_2xhalf_to_float(<2 x half> %a) #0 {
1021+
%r = bitcast <2 x half> %a to float
1022+
ret float %r
1023+
}
10051024

10061025
declare <2 x half> @llvm.sqrt.f16(<2 x half> %a) #0
10071026
declare <2 x half> @llvm.powi.f16.i32(<2 x half> %a, <2 x i32> %b) #0

0 commit comments

Comments
 (0)