Skip to content

Commit

Permalink
[DPWBS-1386] Adding legality rule for G_IMPLICIT_DEF and the correspo…
Browse files Browse the repository at this point in the history
…nding test cases and fix implicit-def/ext/merge-values legalize tests.
  • Loading branch information
Zoltan Toth committed Mar 13, 2020
1 parent 2a10f2f commit 1b46ee0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 45 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Target/TriCore/TriCoreLegalizerInfo.cpp
Expand Up @@ -70,10 +70,10 @@ TriCoreLegalizerInfo::TriCoreLegalizerInfo(const TriCoreSubtarget &ST) {
const LLT s32 = LLT::scalar(32);
const LLT s64 = LLT::scalar(64);

// at least one G_IMPLICIT_DEF must be legal. we allow all types
// G_IMPLICIT_DEF must be legal for p0/s32/s64 tpes
getActionDefinitionsBuilder(G_IMPLICIT_DEF)
.legalFor({p0, s1, s8, s16, s32, s64})
.clampScalar(0, s8, s64)
.legalFor({p0, s32, s64})
.clampScalar(0, s32, s64)
.widenScalarToNextPow2(0);

// G_PHI should be legal for all consumed types to avoid unnecessary
Expand Down
36 changes: 20 additions & 16 deletions llvm/test/CodeGen/TriCore/GlobalIsel/legalize-ext.mir
Expand Up @@ -64,24 +64,28 @@ body: |
; CHECK: $d4 = COPY [[AND4]](s32)
; CHECK: [[TRUNC14:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
; CHECK: $d4 = COPY [[TRUNC14]](s32)
; CHECK: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK: $d4 = COPY [[C4]](s32)
; CHECK: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK: $d4 = COPY [[C5]](s32)
; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: $d4 = COPY [[DEF]](s32)
; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY $d4
; CHECK: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[COPY6]](s32)
; CHECK: $e4 = COPY [[ANYEXT]](s64)
; CHECK: [[COPY7:%[0-9]+]]:_(s32) = COPY [[TRUNC6]](s32)
; CHECK: [[SEXT_INREG6:%[0-9]+]]:_(s32) = G_SEXT_INREG [[COPY7]], 5
; CHECK: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
; CHECK: [[AND5:%[0-9]+]]:_(s32) = G_AND [[COPY6]], [[C4]]
; CHECK: $d4 = COPY [[AND5]](s32)
; CHECK: [[COPY7:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
; CHECK: [[SEXT_INREG6:%[0-9]+]]:_(s32) = G_SEXT_INREG [[COPY7]], 16
; CHECK: $d4 = COPY [[SEXT_INREG6]](s32)
; CHECK: [[COPY8:%[0-9]+]]:_(s64) = COPY [[COPY]](s64)
; CHECK: $e4 = COPY [[COPY8]](s64)
; CHECK: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 31
; CHECK: [[COPY9:%[0-9]+]]:_(s32) = COPY [[TRUNC6]](s32)
; CHECK: [[AND5:%[0-9]+]]:_(s32) = G_AND [[COPY9]], [[C6]]
; CHECK: G_STORE [[AND5]](s32), [[COPY1]](p0) :: (store 1)
; CHECK: [[COPY8:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
; CHECK: $d4 = COPY [[COPY8]](s32)
; CHECK: [[COPY9:%[0-9]+]]:_(s32) = COPY $d4
; CHECK: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[COPY9]](s32)
; CHECK: $e4 = COPY [[ANYEXT]](s64)
; CHECK: [[COPY10:%[0-9]+]]:_(s32) = COPY [[TRUNC6]](s32)
; CHECK: [[SEXT_INREG7:%[0-9]+]]:_(s32) = G_SEXT_INREG [[COPY10]], 5
; CHECK: $d4 = COPY [[SEXT_INREG7]](s32)
; CHECK: [[COPY11:%[0-9]+]]:_(s64) = COPY [[COPY]](s64)
; CHECK: $e4 = COPY [[COPY11]](s64)
; CHECK: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 31
; CHECK: [[COPY12:%[0-9]+]]:_(s32) = COPY [[TRUNC6]](s32)
; CHECK: [[AND6:%[0-9]+]]:_(s32) = G_AND [[COPY12]], [[C5]]
; CHECK: G_STORE [[AND6]](s32), [[COPY1]](p0) :: (store 1)
%0:_(s64) = COPY $e4
%30:_(p0) = COPY $a4
%1:_(s1) = G_TRUNC %0(s64)
Expand Down
45 changes: 25 additions & 20 deletions llvm/test/CodeGen/TriCore/GlobalIsel/legalize-implicit-def.mir
@@ -1,21 +1,25 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -O0 -mtriple=tricore -global-isel -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s
---
name: test_legal_implicit_def
body: |
bb.0.entry:
; CHECK-LABEL: name: test_legal_implicit_def
; CHECK: [[P0:%[0-9]+]]:_(p0) = G_IMPLICIT_DEF
; CHECK: $a2 = COPY [[P0]]
; CHECK: [[S1:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: $d2 = COPY [[S1]]
; CHECK: [[S8:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: $d2 = COPY [[S8]]
; CHECK: [[S16:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: $d2 = COPY [[S16]]
; CHECK: [[S32:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: $d2 = COPY [[S32]]
; CHECK: [[S64:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
; CHECK: $e2 = COPY [[S64]]
; CHECK: [[DEF:%[0-9]+]]:_(p0) = G_IMPLICIT_DEF
; CHECK: $a2 = COPY [[DEF]](p0)
; CHECK: [[DEF1:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[DEF1]](s32)
; CHECK: $d2 = COPY [[COPY]](s32)
; CHECK: [[DEF2:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY [[DEF2]](s32)
; CHECK: $d2 = COPY [[COPY1]](s32)
; CHECK: [[DEF3:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[DEF3]](s32)
; CHECK: $d2 = COPY [[COPY2]](s32)
; CHECK: [[DEF4:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: $d2 = COPY [[DEF4]](s32)
; CHECK: [[DEF5:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
; CHECK: $e2 = COPY [[DEF5]](s64)
%0:_(p0) = G_IMPLICIT_DEF
$a2 = COPY %0(p0)
%1:_(s1) = G_IMPLICIT_DEF
Expand All @@ -37,14 +41,15 @@ name: test_other_implicit_def
body: |
bb.0.entry:
; CHECK-LABEL: name: test_other_implicit_def
; CHECK: [[S3:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: $d2 = COPY [[S3]]
; CHECK: [[S192_1:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
; CHECK: [[S192_2:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
; CHECK: [[S192_3:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
; CHECK: $e2 = COPY [[S192_1]]
; CHECK: $e2 = COPY [[S192_2]]
; CHECK: $e2 = COPY [[S192_3]]
; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
; CHECK: $d2 = COPY [[COPY]](s32)
; CHECK: [[DEF1:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
; CHECK: [[DEF2:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
; CHECK: [[DEF3:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
; CHECK: $e2 = COPY [[DEF1]](s64)
; CHECK: $e2 = COPY [[DEF2]](s64)
; CHECK: $e2 = COPY [[DEF3]](s64)
%0:_(s3) = G_IMPLICIT_DEF
%1:_(s32) = G_ANYEXT %0:_(s3)
$d2 = COPY %1(s32)
Expand Down
13 changes: 7 additions & 6 deletions llvm/test/CodeGen/TriCore/GlobalIsel/legalize-merge-values.mir
Expand Up @@ -150,6 +150,7 @@ body: |
; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
; CHECK: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[C3]](s32)
Expand All @@ -169,14 +170,14 @@ body: |
; CHECK: [[COPY4:%[0-9]+]]:_(s32) = COPY [[C7]](s32)
; CHECK: [[AND3:%[0-9]+]]:_(s32) = G_AND [[COPY4]], [[C8]]
; CHECK: [[C9:%[0-9]+]]:_(s32) = G_CONSTANT i32 15
; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
; CHECK: [[AND4:%[0-9]+]]:_(s32) = G_AND [[DEF]], [[C9]]
; CHECK: [[COPY5:%[0-9]+]]:_(s32) = COPY [[DEF]](s32)
; CHECK: [[AND4:%[0-9]+]]:_(s32) = G_AND [[COPY5]], [[C9]]
; CHECK: [[SHL1:%[0-9]+]]:_(s32) = G_SHL [[AND4]], [[AND3]](s32)
; CHECK: [[C10:%[0-9]+]]:_(s32) = G_CONSTANT i32 15
; CHECK: [[COPY5:%[0-9]+]]:_(s32) = COPY [[C2]](s32)
; CHECK: [[AND5:%[0-9]+]]:_(s32) = G_AND [[COPY5]], [[C10]]
; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[SHL1]](s32)
; CHECK: [[OR1:%[0-9]+]]:_(s32) = G_OR [[AND5]], [[COPY6]]
; CHECK: [[COPY6:%[0-9]+]]:_(s32) = COPY [[C2]](s32)
; CHECK: [[AND5:%[0-9]+]]:_(s32) = G_AND [[COPY6]], [[C10]]
; CHECK: [[COPY7:%[0-9]+]]:_(s32) = COPY [[SHL1]](s32)
; CHECK: [[OR1:%[0-9]+]]:_(s32) = G_OR [[AND5]], [[COPY7]]
; CHECK: [[TRUNC1:%[0-9]+]]:_(s8) = G_TRUNC [[OR1]](s32)
; CHECK: [[MV:%[0-9]+]]:_(s16) = G_MERGE_VALUES [[TRUNC]](s8), [[TRUNC1]](s8)
; CHECK: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[MV]](s16)
Expand Down

0 comments on commit 1b46ee0

Please sign in to comment.