From 5adbf7d57ff669d378829ece1052f3760bf5ab1d Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 21 Jan 2020 20:22:57 -0500 Subject: [PATCH] AMDGPU/GlobalISel: Make G_TRUNC legal This is required to be legal. I'm not sure how we were getting away without defining any rules for it. --- .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp | 3 + .../AMDGPU/GlobalISel/legalize-trunc.mir | 124 ++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-trunc.mir diff --git a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp index c166089443ae..be98f74de953 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp @@ -460,6 +460,9 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_, FMad.scalarize(0) .lower(); + getActionDefinitionsBuilder(G_TRUNC) + .alwaysLegal(); + getActionDefinitionsBuilder({G_SEXT, G_ZEXT, G_ANYEXT}) .legalFor({{S64, S32}, {S32, S16}, {S64, S16}, {S32, S1}, {S64, S1}, {S16, S1}}) diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-trunc.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-trunc.mir new file mode 100644 index 000000000000..7f6f3fb8d3a8 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-trunc.mir @@ -0,0 +1,124 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=fiji -run-pass=legalizer -global-isel-abort=0 -o - %s | FileCheck %s + +--- +name: test_trunc_s64_to_s32 +body: | + bb.0: + liveins: $vgpr0_vgpr1 + + ; CHECK-LABEL: name: test_trunc_s64_to_s32 + ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1 + ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64) + ; CHECK: $vgpr0 = COPY [[TRUNC]](s32) + %0:_(s64) = COPY $vgpr0_vgpr1 + %1:_(s32) = G_TRUNC %0 + $vgpr0 = COPY %1 +... + +--- +name: test_trunc_s64_to_s16 +body: | + bb.0: + liveins: $vgpr0_vgpr1 + + ; CHECK-LABEL: name: test_trunc_s64_to_s16 + ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1 + ; CHECK: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s64) + ; CHECK: S_ENDPGM 0, implicit [[TRUNC]](s16) + %0:_(s64) = COPY $vgpr0_vgpr1 + %1:_(s16) = G_TRUNC %0 + S_ENDPGM 0, implicit %1 +... + +--- +name: test_trunc_v2s32_to_v2s16 +body: | + bb.0: + liveins: $vgpr0_vgpr1 + + ; CHECK-LABEL: name: test_trunc_v2s32_to_v2s16 + ; CHECK: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $vgpr0_vgpr1 + ; CHECK: [[TRUNC:%[0-9]+]]:_(<2 x s16>) = G_TRUNC [[COPY]](<2 x s32>) + ; CHECK: $vgpr0 = COPY [[TRUNC]](<2 x s16>) + %0:_(<2 x s32>) = COPY $vgpr0_vgpr1 + %1:_(<2 x s16>) = G_TRUNC %0 + $vgpr0 = COPY %1 +... + +--- +name: test_trunc_v4s32_to_v4s16 +body: | + bb.0: + liveins: $vgpr0_vgpr1_vgpr2_vgpr3 + + ; CHECK-LABEL: name: test_trunc_v4s32_to_v4s16 + ; CHECK: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3 + ; CHECK: [[TRUNC:%[0-9]+]]:_(<4 x s16>) = G_TRUNC [[COPY]](<4 x s32>) + ; CHECK: $vgpr0_vgpr1 = COPY [[TRUNC]](<4 x s16>) + %0:_(<4 x s32>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3 + %1:_(<4 x s16>) = G_TRUNC %0 + $vgpr0_vgpr1 = COPY %1 +... + +--- +name: test_trunc_s64_to_s1 +body: | + bb.0: + liveins: $vgpr0_vgpr1 + + ; CHECK-LABEL: name: test_trunc_s64_to_s1 + ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1 + ; CHECK: [[TRUNC:%[0-9]+]]:_(s1) = G_TRUNC [[COPY]](s64) + ; CHECK: S_ENDPGM 0, implicit [[TRUNC]](s1) + %0:_(s64) = COPY $vgpr0_vgpr1 + %1:_(s1) = G_TRUNC %0 + S_ENDPGM 0, implicit %1 +... + +--- +name: test_trunc_s32_to_s1 +body: | + bb.0: + liveins: $vgpr0 + + ; CHECK-LABEL: name: test_trunc_s32_to_s1 + ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0 + ; CHECK: [[TRUNC:%[0-9]+]]:_(s1) = G_TRUNC [[COPY]](s32) + ; CHECK: S_ENDPGM 0, implicit [[TRUNC]](s1) + %0:_(s32) = COPY $vgpr0 + %1:_(s1) = G_TRUNC %0 + S_ENDPGM 0, implicit %1 +... + +--- +name: test_trunc_s16_to_s1 +body: | + bb.0: + liveins: $vgpr0 + + ; CHECK-LABEL: name: test_trunc_s16_to_s1 + ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0 + ; CHECK: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32) + ; CHECK: [[TRUNC1:%[0-9]+]]:_(s1) = G_TRUNC [[TRUNC]](s16) + ; CHECK: S_ENDPGM 0, implicit [[TRUNC1]](s1) + %0:_(s32) = COPY $vgpr0 + %1:_(s16) = G_TRUNC %0 + %2:_(s1) = G_TRUNC %1 + S_ENDPGM 0, implicit %2 +... + +--- +name: test_trunc_v4s32_to_v4s1 +body: | + bb.0: + liveins: $vgpr0_vgpr1_vgpr2_vgpr3 + + ; CHECK-LABEL: name: test_trunc_v4s32_to_v4s1 + ; CHECK: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3 + ; CHECK: [[TRUNC:%[0-9]+]]:_(<4 x s1>) = G_TRUNC [[COPY]](<4 x s32>) + ; CHECK: S_ENDPGM 0, implicit [[TRUNC]](<4 x s1>) + %0:_(<4 x s32>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3 + %1:_(<4 x s1>) = G_TRUNC %0 + S_ENDPGM 0, implicit %1 +...