Skip to content

Commit

Permalink
[DPWBS-1188] Adding legality rule for G_FABS and the corresponding te…
Browse files Browse the repository at this point in the history
…st cases.
  • Loading branch information
davidferencszabo committed Jan 31, 2020
1 parent 50eade6 commit 8f07d2e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
8 changes: 7 additions & 1 deletion llvm/lib/Target/TriCore/TriCoreLegalizerInfo.cpp
Expand Up @@ -211,7 +211,7 @@ TriCoreLegalizerInfo::TriCoreLegalizerInfo(const TriCoreSubtarget &ST) {
.clampScalar(0, s32, s64)
.widenScalarToNextPow2(0);

// Floating Point Conversions
// Floating Point Unary Ops

// G_FPTOSI and G_FPTOUI are legal for s32 and s64 combinations, except for
// {s64, s32}
Expand Down Expand Up @@ -241,6 +241,12 @@ TriCoreLegalizerInfo::TriCoreLegalizerInfo(const TriCoreSubtarget &ST) {
else
IntToFPConvActions.libcallFor({{s64, s32}, {s64, s64}});

// G_FABS legal for s32 and s64
getActionDefinitionsBuilder(G_FABS)
.legalFor({s32, s64})
.clampScalar(0, s32, s64)
.widenScalarToNextPow2(0);

// Load & Store

// G_LOAD is legal for 32 and 64-bit scalar and pointer types.
Expand Down
56 changes: 56 additions & 0 deletions llvm/test/CodeGen/TriCore/GlobalIsel/legalize-fabs.mir
@@ -0,0 +1,56 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -O0 -mtriple=tricore -global-isel -run-pass=legalizer \
# RUN: -verify-machineinstrs %s -o - | FileCheck %s


---
name: fabs_s32
body: |
bb.0:
liveins: $d4
; CHECK-LABEL: name: fabs_s32
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $d4
; CHECK: [[FABS:%[0-9]+]]:_(s32) = G_FABS [[COPY]]
; CHECK: $d4 = COPY [[FABS]](s32)
%0:_(s32) = COPY $d4
%1:_(s32) = G_FABS %0(s32)
$d4 = COPY %1(s32)
...

---
name: fabs_s64
body: |
bb.0:
liveins: $e4
; CHECK-LABEL: name: fabs_s64
; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $e4
; CHECK: [[FABS:%[0-9]+]]:_(s64) = G_FABS [[COPY]]
; CHECK: $e4 = COPY [[FABS]](s64)
%0:_(s64) = COPY $e4
%1:_(s64) = G_FABS %0(s64)
$e4 = COPY %1(s64)
...

---
name: fabs_smaller_than_s32
body: |
bb.0:
liveins: $d4
; CHECK-LABEL: name: fabs_smaller_than_s32
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $d4
; CHECK: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32)
; CHECK: [[FPEXT:%[0-9]+]]:_(s32) = G_FPEXT [[TRUNC]](s16)
; CHECK: [[FABS:%[0-9]+]]:_(s32) = G_FABS [[FPEXT]]
; CHECK: [[FPTRUNC:%[0-9]+]]:_(s16) = G_FPTRUNC [[FABS]](s32)
; CHECK: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[FPTRUNC]](s16)
; CHECK: $d4 = COPY [[ANYEXT]](s32)
%0:_(s32) = COPY $d4
%1:_(s16) = G_TRUNC %0:_(s32)
%2:_(s16) = G_FABS %1
%3:_(s32) = G_ANYEXT %2:_(s16)
$d4 = COPY %3
...

0 comments on commit 8f07d2e

Please sign in to comment.