Skip to content

Commit 3118926

Browse files
author
Jessica Paquette
committed
[GlobalISel] Add a G_LROUND instruction
Meant to represent the `@llvm.lround.*` family. Add the opcode, docs, and verification. Differential Revision: https://reviews.llvm.org/D108417
1 parent 4bb36df commit 3118926

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

llvm/docs/GlobalISel/GenericOpcode.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,19 @@ G_INTRINSIC_ROUND
573573

574574
Returns the operand rounded to the nearest integer.
575575

576+
G_LROUND
577+
^^^^^^^^
578+
579+
Returns the source operand rounded to the nearest integer with ties away from
580+
zero.
581+
582+
See the LLVM LangRef entry on '``llvm.lround.*'`` for details on behaviour.
583+
584+
.. code-block:: none
585+
586+
%rounded_32:_(s32) = G_LROUND %round_me:_(s64)
587+
%rounded_64:_(s64) = G_LROUND %round_me:_(s64)
588+
576589
Vector Specific Operations
577590
--------------------------
578591

llvm/include/llvm/Support/TargetOpcodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ HANDLE_TARGET_OPCODE(G_UMAX)
652652
/// Generic integer absolute value.
653653
HANDLE_TARGET_OPCODE(G_ABS)
654654

655+
HANDLE_TARGET_OPCODE(G_LROUND)
656+
655657
/// Generic BRANCH instruction. This is an unconditional branch.
656658
HANDLE_TARGET_OPCODE(G_BR)
657659

llvm/include/llvm/Target/GenericOpcodes.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ def G_ISNAN: GenericInstruction {
232232
let hasSideEffects = false;
233233
}
234234

235+
def G_LROUND: GenericInstruction {
236+
let OutOperandList = (outs type0:$dst);
237+
let InOperandList = (ins type1:$src);
238+
let hasSideEffects = false;
239+
}
240+
235241
//------------------------------------------------------------------------------
236242
// Binary ops.
237243
//------------------------------------------------------------------------------

llvm/include/llvm/Target/GlobalISel/SelectionDAGCompat.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def : GINodeEquiv<G_FMAXNUM_IEEE, fmaxnum_ieee>;
144144
def : GINodeEquiv<G_READCYCLECOUNTER, readcyclecounter>;
145145
def : GINodeEquiv<G_ROTR, rotr>;
146146
def : GINodeEquiv<G_ROTL, rotl>;
147+
def : GINodeEquiv<G_LROUND, lround>;
147148

148149
def : GINodeEquiv<G_STRICT_FADD, strict_fadd>;
149150
def : GINodeEquiv<G_STRICT_FSUB, strict_fsub>;

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,13 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
16151615
break;
16161616
}
16171617

1618+
case TargetOpcode::G_LROUND: {
1619+
if (!MRI->getType(MI->getOperand(0).getReg()).isScalar() ||
1620+
!MRI->getType(MI->getOperand(1).getReg()).isScalar())
1621+
report("lround only supports scalars", MI);
1622+
break;
1623+
}
1624+
16181625
default:
16191626
break;
16201627
}

llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,9 @@
526526
# DEBUG-NEXT: G_ABS (opcode {{[0-9]+}}): 1 type index, 0 imm indices
527527
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
528528
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
529+
# DEBUG-NEXT: G_LROUND (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
530+
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
531+
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
529532
# DEBUG-NEXT: G_BR (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
530533
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
531534
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#RUN: not --crash llc -march=aarch64 -o - -global-isel -run-pass=none -verify-machineinstrs %s 2>&1 | FileCheck %s
2+
# REQUIRES: aarch64-registered-target
3+
4+
---
5+
name: test_lround
6+
legalized: true
7+
regBankSelected: false
8+
selected: false
9+
tracksRegLiveness: true
10+
liveins:
11+
body: |
12+
bb.0:
13+
liveins: $x0, $q0
14+
%ptr:_(p0) = COPY $x0
15+
%vector:_(<2 x s64>) = COPY $q0
16+
17+
; CHECK: Bad machine code: lround only supports scalars
18+
; CHECK: instruction: %no_ptrs:_(s32) = G_LROUND %ptr:_(p0)
19+
%no_ptrs:_(s32) = G_LROUND %ptr:_(p0)
20+
21+
; CHECK: Bad machine code: lround only supports scalars
22+
; CHECK: instruction: %no_vectors:_(s32) = G_LROUND %vector:_(<2 x s64>)
23+
%no_vectors:_(s32) = G_LROUND %vector:_(<2 x s64>)

0 commit comments

Comments
 (0)