Skip to content

Commit

Permalink
[AArch64][GlobalISel] Add legalization & selection support for G_INTR…
Browse files Browse the repository at this point in the history
…INSIC_LRINT.

Differential Revision: https://reviews.llvm.org/D84552
  • Loading branch information
aemerson committed Jul 30, 2020
1 parent abb8128 commit 09f9f7d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 3 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/Target/GlobalISel/SelectionDAGCompat.td
Expand Up @@ -125,6 +125,7 @@ def : GINodeEquiv<G_FRINT, frint>;
def : GINodeEquiv<G_FNEARBYINT, fnearbyint>;
def : GINodeEquiv<G_INTRINSIC_TRUNC, ftrunc>;
def : GINodeEquiv<G_INTRINSIC_ROUND, fround>;
def : GINodeEquiv<G_INTRINSIC_LRINT, lrint>;
def : GINodeEquiv<G_FCOPYSIGN, fcopysign>;
def : GINodeEquiv<G_SMIN, smin>;
def : GINodeEquiv<G_SMAX, smax>;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
Expand Up @@ -156,7 +156,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)

getActionDefinitionsBuilder({G_FCEIL, G_FABS, G_FSQRT, G_FFLOOR, G_FRINT,
G_FMA, G_INTRINSIC_TRUNC, G_INTRINSIC_ROUND,
G_FNEARBYINT})
G_FNEARBYINT, G_INTRINSIC_LRINT})
// If we don't have full FP16 support, then scalarize the elements of
// vectors containing fp16 types.
.fewerElementsIf(
Expand Down
94 changes: 94 additions & 0 deletions llvm/test/CodeGen/AArch64/GlobalISel/legalize-lrint.mir
@@ -0,0 +1,94 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -verify-machineinstrs -mtriple aarch64-unknown-unknown -run-pass=legalizer %s -o - | FileCheck %s
---
name: testmsws
alignment: 4
tracksRegLiveness: true
liveins:
- { reg: '$s0' }
body: |
bb.1:
liveins: $s0
; CHECK-LABEL: name: testmsws
; CHECK: liveins: $s0
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
; CHECK: [[INTRINSIC_LRINT:%[0-9]+]]:_(s64) = G_INTRINSIC_LRINT [[COPY]](s32)
; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[INTRINSIC_LRINT]](s64)
; CHECK: $w0 = COPY [[TRUNC]](s32)
; CHECK: RET_ReallyLR implicit $w0
%0:_(s32) = COPY $s0
%1:_(s64) = G_INTRINSIC_LRINT %0(s32)
%2:_(s32) = G_TRUNC %1(s64)
$w0 = COPY %2(s32)
RET_ReallyLR implicit $w0
...
---
name: testmsxs
alignment: 4
tracksRegLiveness: true
liveins:
- { reg: '$s0' }
body: |
bb.1:
liveins: $s0
; CHECK-LABEL: name: testmsxs
; CHECK: liveins: $s0
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
; CHECK: [[INTRINSIC_LRINT:%[0-9]+]]:_(s64) = G_INTRINSIC_LRINT [[COPY]](s32)
; CHECK: $x0 = COPY [[INTRINSIC_LRINT]](s64)
; CHECK: RET_ReallyLR implicit $x0
%0:_(s32) = COPY $s0
%1:_(s64) = G_INTRINSIC_LRINT %0(s32)
$x0 = COPY %1(s64)
RET_ReallyLR implicit $x0
...
---
name: testmswd
alignment: 4
tracksRegLiveness: true
liveins:
- { reg: '$d0' }
body: |
bb.1:
liveins: $d0
; CHECK-LABEL: name: testmswd
; CHECK: liveins: $d0
; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $d0
; CHECK: [[INTRINSIC_LRINT:%[0-9]+]]:_(s64) = G_INTRINSIC_LRINT [[COPY]](s64)
; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[INTRINSIC_LRINT]](s64)
; CHECK: $w0 = COPY [[TRUNC]](s32)
; CHECK: RET_ReallyLR implicit $w0
%0:_(s64) = COPY $d0
%1:_(s64) = G_INTRINSIC_LRINT %0(s64)
%2:_(s32) = G_TRUNC %1(s64)
$w0 = COPY %2(s32)
RET_ReallyLR implicit $w0
...
---
name: testmsxd
alignment: 4
tracksRegLiveness: true
liveins:
- { reg: '$d0' }
body: |
bb.1:
liveins: $d0
; CHECK-LABEL: name: testmsxd
; CHECK: liveins: $d0
; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $d0
; CHECK: [[INTRINSIC_LRINT:%[0-9]+]]:_(s64) = G_INTRINSIC_LRINT [[COPY]](s64)
; CHECK: $x0 = COPY [[INTRINSIC_LRINT]](s64)
; CHECK: RET_ReallyLR implicit $x0
%0:_(s64) = COPY $d0
%1:_(s64) = G_INTRINSIC_LRINT %0(s64)
$x0 = COPY %1(s64)
RET_ReallyLR implicit $x0
...
Expand Up @@ -130,8 +130,9 @@
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
# DEBUG-NEXT: G_INTRINSIC_LRINT (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
# DEBUG-NEXT:.. imm index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
# DEBUG-NEXT: G_INTRINSIC_ROUNDEVEN (opcode {{[0-9]+}}): 1 type index, 0 imm indices
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
Expand Down
5 changes: 5 additions & 0 deletions llvm/test/CodeGen/AArch64/lrint-conv.ll
@@ -1,9 +1,11 @@
; RUN: llc < %s -mtriple=aarch64 -mattr=+neon | FileCheck %s
; RUN: llc < %s -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=aarch64 | FileCheck %s --check-prefixes=FALLBACK,CHECK

; CHECK-LABEL: testmsws:
; CHECK: frintx [[REG:s[0-9]]], s0
; CHECK-NEXT: fcvtzs x0, [[REG]]
; CHECK: ret
; FALLBACK-NOT: remark{{.*}}testmsws
define i32 @testmsws(float %x) {
entry:
%0 = tail call i64 @llvm.lrint.i64.f32(float %x)
Expand All @@ -15,6 +17,7 @@ entry:
; CHECK: frintx [[REG:s[0-9]]], s0
; CHECK-NEXT: fcvtzs x0, [[REG]]
; CHECK-NEXT: ret
; FALLBACK-NOT: remark{{.*}}testmsxs
define i64 @testmsxs(float %x) {
entry:
%0 = tail call i64 @llvm.lrint.i64.f32(float %x)
Expand All @@ -25,6 +28,7 @@ entry:
; CHECK: frintx [[REG:d[0-9]]], d0
; CHECK-NEXT: fcvtzs x0, [[REG]]
; CHECK: ret
; FALLBACK-NOT: remark{{.*}}testmswd
define i32 @testmswd(double %x) {
entry:
%0 = tail call i64 @llvm.lrint.i64.f64(double %x)
Expand All @@ -36,6 +40,7 @@ entry:
; CHECK: frintx [[REG:d[0-9]]], d0
; CHECK-NEXT: fcvtzs x0, [[REG]]
; CHECK-NEXT: ret
; FALLBACK-NOT: remark{{.*}}testmsxd
define i64 @testmsxd(double %x) {
entry:
%0 = tail call i64 @llvm.lrint.i64.f64(double %x)
Expand Down

0 comments on commit 09f9f7d

Please sign in to comment.