Skip to content

Commit 9d03135

Browse files
davemgreengithub-actions[bot]
authored andcommitted
Automerge: [AArch64][GlobalISel] Add better basic legalization for llround. (#168427)
This adds handling for f16 and f128 lround/llround under LP64 targets, promoting the f16 where needed and using a libcall for f128. This codegen is now identical to the selection dag version.
2 parents 48d0cef + 4ecfaa6 commit 9d03135

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,6 +3439,18 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
34393439
Observer.changedInstr(MI);
34403440
return Legalized;
34413441
}
3442+
case TargetOpcode::G_LROUND:
3443+
case TargetOpcode::G_LLROUND:
3444+
Observer.changingInstr(MI);
3445+
3446+
if (TypeIdx == 0)
3447+
widenScalarDst(MI, WideTy);
3448+
else
3449+
widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_FPEXT);
3450+
3451+
Observer.changedInstr(MI);
3452+
return Legalized;
3453+
34423454
case TargetOpcode::G_INTTOPTR:
34433455
if (TypeIdx != 1)
34443456
return UnableToLegalize;

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,12 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
449449
.minScalar(0, s32)
450450
.libcallFor({{s32, s32}, {s64, s32}, {s128, s32}});
451451

452-
// TODO: Libcall support for s128.
453-
// TODO: s16 should be legal with full FP16 support.
454452
getActionDefinitionsBuilder({G_LROUND, G_LLROUND})
455-
.legalFor({{s64, s32}, {s64, s64}});
453+
.legalFor({{s64, s32}, {s64, s64}})
454+
.legalFor(HasFP16, {{s64, s16}})
455+
.minScalar(0, s64)
456+
.minScalar(1, s32)
457+
.libcallFor({{s64, s128}});
456458

457459
// TODO: Custom legalization for mismatched types.
458460
getActionDefinitionsBuilder(G_FCOPYSIGN)

llvm/test/CodeGen/AArch64/llround-conv-fp16.ll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
22
; RUN: llc < %s -mtriple=aarch64 | FileCheck %s --check-prefixes=CHECK-NOFP16
33
; RUN: llc < %s -mtriple=aarch64 -mattr=+fullfp16 | FileCheck %s --check-prefixes=CHECK-FP16
4-
; RUN: llc < %s -mtriple=aarch64 -global-isel -global-isel-abort=2 2>&1 | FileCheck %s --check-prefixes=CHECK-NOFP16,CHECK-GI
5-
; RUN: llc < %s -mtriple=aarch64 -mattr=+fullfp16 -global-isel -global-isel-abort=2 2>&1 | FileCheck %s --check-prefixes=CHECK-FP16,CHECK-GI
6-
7-
; CHECK-GI: warning: Instruction selection used fallback path for testmhhs
8-
; CHECK-GI-NEXT: warning: Instruction selection used fallback path for testmhws
9-
; CHECK-GI-NEXT: warning: Instruction selection used fallback path for testmhxs
4+
; RUN: llc < %s -mtriple=aarch64 -global-isel | FileCheck %s --check-prefixes=CHECK-NOFP16
5+
; RUN: llc < %s -mtriple=aarch64 -mattr=+fullfp16 -global-isel | FileCheck %s --check-prefixes=CHECK-FP16
106

117
define i16 @testmhhs(half %x) {
128
; CHECK-NOFP16-LABEL: testmhhs:

llvm/test/CodeGen/AArch64/llround-conv.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
22
; RUN: llc < %s -mtriple=aarch64 -mattr=+neon | FileCheck %s
3-
; RUN: llc < %s -mtriple=aarch64 -mattr=+neon -global-isel -global-isel-abort=2 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-GI
4-
5-
; CHECK-GI: warning: Instruction selection used fallback path for testmswl
6-
; CHECK-GI-NEXT: warning: Instruction selection used fallback path for testmsll
3+
; RUN: llc < %s -mtriple=aarch64 -mattr=+neon -global-isel | FileCheck %s
74

85
define i32 @testmsws(float %x) {
96
; CHECK-LABEL: testmsws:

llvm/test/CodeGen/AArch64/lround-conv-fp16.ll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
22
; RUN: llc < %s -mtriple=aarch64 | FileCheck %s --check-prefixes=CHECK-NOFP16
33
; RUN: llc < %s -mtriple=aarch64 -mattr=+fullfp16 | FileCheck %s --check-prefixes=CHECK-FP16
4-
; RUN: llc < %s -mtriple=aarch64 -global-isel -global-isel-abort=2 2>&1 | FileCheck %s --check-prefixes=CHECK-NOFP16,CHECK-GI
5-
; RUN: llc < %s -mtriple=aarch64 -mattr=+fullfp16 -global-isel -global-isel-abort=2 2>&1 | FileCheck %s --check-prefixes=CHECK-FP16,CHECK-GI
6-
7-
; CHECK-GI: warning: Instruction selection used fallback path for testmhhs
8-
; CHECK-GI-NEXT: warning: Instruction selection used fallback path for testmhws
9-
; CHECK-GI-NEXT: warning: Instruction selection used fallback path for testmhxs
4+
; RUN: llc < %s -mtriple=aarch64 -global-isel | FileCheck %s --check-prefixes=CHECK-NOFP16
5+
; RUN: llc < %s -mtriple=aarch64 -mattr=+fullfp16 -global-isel | FileCheck %s --check-prefixes=CHECK-FP16
106

117
define i16 @testmhhs(half %x) {
128
; CHECK-NOFP16-LABEL: testmhhs:

llvm/test/CodeGen/AArch64/lround-conv.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
22
; RUN: llc < %s -mtriple=aarch64 -mattr=+neon | FileCheck %s
3-
; RUN: llc < %s -mtriple=aarch64 -mattr=+neon -global-isel -global-isel-abort=2 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-GI
4-
5-
; CHECK-GI: warning: Instruction selection used fallback path for testmswl
6-
; CHECK-GI-NEXT: warning: Instruction selection used fallback path for testmsll
3+
; RUN: llc < %s -mtriple=aarch64 -mattr=+neon -global-isel | FileCheck %s
74

85
define i32 @testmsws(float %x) {
96
; CHECK-LABEL: testmsws:

0 commit comments

Comments
 (0)