AMDGPU/GlobalISel: Legalize f32->f16 fptrunc

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351695 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp b/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
index f02c93d..61d344a 100644
--- a/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
+++ b/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
@@ -139,7 +139,7 @@
     .legalFor({S32, S64});
 
   getActionDefinitionsBuilder(G_FPTRUNC)
-    .legalFor({{S32, S64}});
+    .legalFor({{S32, S64}, {S16, S32}});
 
   getActionDefinitionsBuilder(G_FPEXT)
     .legalFor({{S64, S32}, {S32, S16}})
diff --git a/test/CodeGen/AMDGPU/GlobalISel/legalize-fptrunc.mir b/test/CodeGen/AMDGPU/GlobalISel/legalize-fptrunc.mir
index 40eae26..f2ed866 100644
--- a/test/CodeGen/AMDGPU/GlobalISel/legalize-fptrunc.mir
+++ b/test/CodeGen/AMDGPU/GlobalISel/legalize-fptrunc.mir
@@ -2,12 +2,12 @@
 # RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=fiji -run-pass=legalizer -global-isel %s -o - | FileCheck %s
 
 ---
-name: test_fptrunc_f64_to_f32
+name: test_fptrunc_s64_to_s32
 body: |
   bb.0:
     liveins: $vgpr0_vgpr1
 
-    ; CHECK-LABEL: name: test_fptrunc_f64_to_f32
+    ; CHECK-LABEL: name: test_fptrunc_s64_to_s32
     ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1
     ; CHECK: [[FPTRUNC:%[0-9]+]]:_(s32) = G_FPTRUNC [[COPY]](s64)
     ; CHECK: $vgpr0 = COPY [[FPTRUNC]](s32)
@@ -15,3 +15,20 @@
     %1:_(s32) = G_FPTRUNC %0
     $vgpr0 = COPY %1
 ...
+
+---
+name: test_fptrunc_s32_to_s16
+body: |
+  bb.0:
+    liveins: $vgpr0
+
+    ; CHECK-LABEL: name: test_fptrunc_s32_to_s16
+    ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
+    ; CHECK: [[FPTRUNC:%[0-9]+]]:_(s16) = G_FPTRUNC [[COPY]](s32)
+    ; CHECK: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[FPTRUNC]](s16)
+    ; CHECK: $vgpr0 = COPY [[ANYEXT]](s32)
+    %0:_(s32) = COPY $vgpr0
+    %1:_(s16) = G_FPTRUNC %0
+    %2:_(s32) = G_ANYEXT %1
+    $vgpr0 = COPY %2
+...