Skip to content

Commit 9507254

Browse files
committed
[AArch64] Add more roundeven+conversion tests
These currently aren't compiled into fcvtn* instructions because the libcall isn't properly lowered.
1 parent ea85543 commit 9507254

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed

llvm/test/CodeGen/AArch64/round-fptosi-sat-scalar.ll

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,92 @@ entry:
434434
ret i64 %i
435435
}
436436

437+
; Round to nearest, ties to even (fcvtns).
438+
439+
define i32 @testnswh(half %a) {
440+
; CHECK-CVT-LABEL: testnswh:
441+
; CHECK-CVT: // %bb.0: // %entry
442+
; CHECK-CVT-NEXT: fcvt s0, h0
443+
; CHECK-CVT-NEXT: frintn s0, s0
444+
; CHECK-CVT-NEXT: fcvt h0, s0
445+
; CHECK-CVT-NEXT: fcvt s0, h0
446+
; CHECK-CVT-NEXT: fcvtzs w0, s0
447+
; CHECK-CVT-NEXT: ret
448+
;
449+
; CHECK-FP16-LABEL: testnswh:
450+
; CHECK-FP16: // %bb.0: // %entry
451+
; CHECK-FP16-NEXT: fcvtns w0, h0
452+
; CHECK-FP16-NEXT: ret
453+
entry:
454+
%r = call half @llvm.roundeven.f16(half %a) nounwind readnone
455+
%i = call i32 @llvm.fptosi.sat.i32.f16(half %r)
456+
ret i32 %i
457+
}
458+
459+
define i64 @testnsxh(half %a) {
460+
; CHECK-CVT-LABEL: testnsxh:
461+
; CHECK-CVT: // %bb.0: // %entry
462+
; CHECK-CVT-NEXT: fcvt s0, h0
463+
; CHECK-CVT-NEXT: frintn s0, s0
464+
; CHECK-CVT-NEXT: fcvt h0, s0
465+
; CHECK-CVT-NEXT: fcvt s0, h0
466+
; CHECK-CVT-NEXT: fcvtzs x0, s0
467+
; CHECK-CVT-NEXT: ret
468+
;
469+
; CHECK-FP16-LABEL: testnsxh:
470+
; CHECK-FP16: // %bb.0: // %entry
471+
; CHECK-FP16-NEXT: fcvtns x0, h0
472+
; CHECK-FP16-NEXT: ret
473+
entry:
474+
%r = call half @llvm.roundeven.f16(half %a) nounwind readnone
475+
%i = call i64 @llvm.fptosi.sat.i64.f16(half %r)
476+
ret i64 %i
477+
}
478+
479+
define i32 @testnsws(float %a) {
480+
; CHECK-LABEL: testnsws:
481+
; CHECK: // %bb.0: // %entry
482+
; CHECK-NEXT: fcvtns w0, s0
483+
; CHECK-NEXT: ret
484+
entry:
485+
%r = call float @roundevenf(float %a) nounwind readnone
486+
%i = call i32 @llvm.fptosi.sat.i32.f32(float %r)
487+
ret i32 %i
488+
}
489+
490+
define i64 @testnsxs(float %a) {
491+
; CHECK-LABEL: testnsxs:
492+
; CHECK: // %bb.0: // %entry
493+
; CHECK-NEXT: fcvtns x0, s0
494+
; CHECK-NEXT: ret
495+
entry:
496+
%r = call float @roundevenf(float %a) nounwind readnone
497+
%i = call i64 @llvm.fptosi.sat.i64.f32(float %r)
498+
ret i64 %i
499+
}
500+
501+
define i32 @testnswd(double %a) {
502+
; CHECK-LABEL: testnswd:
503+
; CHECK: // %bb.0: // %entry
504+
; CHECK-NEXT: fcvtns w0, d0
505+
; CHECK-NEXT: ret
506+
entry:
507+
%r = call double @roundeven(double %a) nounwind readnone
508+
%i = call i32 @llvm.fptosi.sat.i32.f64(double %r)
509+
ret i32 %i
510+
}
511+
512+
define i64 @testnsxd(double %a) {
513+
; CHECK-LABEL: testnsxd:
514+
; CHECK: // %bb.0: // %entry
515+
; CHECK-NEXT: fcvtns x0, d0
516+
; CHECK-NEXT: ret
517+
entry:
518+
%r = call double @roundeven(double %a) nounwind readnone
519+
%i = call i64 @llvm.fptosi.sat.i64.f64(double %r)
520+
ret i64 %i
521+
}
522+
437523
declare i32 @llvm.fptosi.sat.i32.bf16 (bfloat)
438524
declare i64 @llvm.fptosi.sat.i64.bf16 (bfloat)
439525
declare i32 @llvm.fptosi.sat.i32.f16 (half)
@@ -451,11 +537,14 @@ declare half @llvm.floor.f16(half) nounwind readnone
451537
declare half @llvm.ceil.f16(half) nounwind readnone
452538
declare half @llvm.trunc.f16(half) nounwind readnone
453539
declare half @llvm.round.f16(half) nounwind readnone
540+
declare half @llvm.roundeven.f16(half) nounwind readnone
454541
declare float @floorf(float) nounwind readnone
455542
declare float @ceilf(float) nounwind readnone
456543
declare float @truncf(float) nounwind readnone
457544
declare float @roundf(float) nounwind readnone
545+
declare float @roundevenf(float) nounwind readnone
458546
declare double @floor(double) nounwind readnone
459547
declare double @ceil(double) nounwind readnone
460548
declare double @trunc(double) nounwind readnone
461549
declare double @round(double) nounwind readnone
550+
declare double @roundeven(double) nounwind readnone

llvm/test/CodeGen/AArch64/round-fptoui-sat-scalar.ll

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,92 @@ entry:
346346
ret i64 %i
347347
}
348348

349+
; Round to nearest, ties to even (fcvtnu).
350+
351+
define i32 @testnuwh(half %a) {
352+
; CHECK-CVT-LABEL: testnuwh:
353+
; CHECK-CVT: // %bb.0: // %entry
354+
; CHECK-CVT-NEXT: fcvt s0, h0
355+
; CHECK-CVT-NEXT: frintn s0, s0
356+
; CHECK-CVT-NEXT: fcvt h0, s0
357+
; CHECK-CVT-NEXT: fcvt s0, h0
358+
; CHECK-CVT-NEXT: fcvtzu w0, s0
359+
; CHECK-CVT-NEXT: ret
360+
;
361+
; CHECK-FP16-LABEL: testnuwh:
362+
; CHECK-FP16: // %bb.0: // %entry
363+
; CHECK-FP16-NEXT: fcvtnu w0, h0
364+
; CHECK-FP16-NEXT: ret
365+
entry:
366+
%r = call half @llvm.roundeven.f16(half %a) nounwind readnone
367+
%i = call i32 @llvm.fptoui.sat.i32.f16(half %r)
368+
ret i32 %i
369+
}
370+
371+
define i64 @testnuxh(half %a) {
372+
; CHECK-CVT-LABEL: testnuxh:
373+
; CHECK-CVT: // %bb.0: // %entry
374+
; CHECK-CVT-NEXT: fcvt s0, h0
375+
; CHECK-CVT-NEXT: frintn s0, s0
376+
; CHECK-CVT-NEXT: fcvt h0, s0
377+
; CHECK-CVT-NEXT: fcvt s0, h0
378+
; CHECK-CVT-NEXT: fcvtzu x0, s0
379+
; CHECK-CVT-NEXT: ret
380+
;
381+
; CHECK-FP16-LABEL: testnuxh:
382+
; CHECK-FP16: // %bb.0: // %entry
383+
; CHECK-FP16-NEXT: fcvtnu x0, h0
384+
; CHECK-FP16-NEXT: ret
385+
entry:
386+
%r = call half @llvm.roundeven.f16(half %a) nounwind readnone
387+
%i = call i64 @llvm.fptoui.sat.i64.f16(half %r)
388+
ret i64 %i
389+
}
390+
391+
define i32 @testnuws(float %a) {
392+
; CHECK-LABEL: testnuws:
393+
; CHECK: // %bb.0: // %entry
394+
; CHECK-NEXT: fcvtnu w0, s0
395+
; CHECK-NEXT: ret
396+
entry:
397+
%r = call float @roundevenf(float %a) nounwind readnone
398+
%i = call i32 @llvm.fptoui.sat.i32.f32(float %r)
399+
ret i32 %i
400+
}
401+
402+
define i64 @testnuxs(float %a) {
403+
; CHECK-LABEL: testnuxs:
404+
; CHECK: // %bb.0: // %entry
405+
; CHECK-NEXT: fcvtnu x0, s0
406+
; CHECK-NEXT: ret
407+
entry:
408+
%r = call float @roundevenf(float %a) nounwind readnone
409+
%i = call i64 @llvm.fptoui.sat.i64.f32(float %r)
410+
ret i64 %i
411+
}
412+
413+
define i32 @testnuwd(double %a) {
414+
; CHECK-LABEL: testnuwd:
415+
; CHECK: // %bb.0: // %entry
416+
; CHECK-NEXT: fcvtnu w0, d0
417+
; CHECK-NEXT: ret
418+
entry:
419+
%r = call double @roundeven(double %a) nounwind readnone
420+
%i = call i32 @llvm.fptoui.sat.i32.f64(double %r)
421+
ret i32 %i
422+
}
423+
424+
define i64 @testnuxd(double %a) {
425+
; CHECK-LABEL: testnuxd:
426+
; CHECK: // %bb.0: // %entry
427+
; CHECK-NEXT: fcvtnu x0, d0
428+
; CHECK-NEXT: ret
429+
entry:
430+
%r = call double @roundeven(double %a) nounwind readnone
431+
%i = call i64 @llvm.fptoui.sat.i64.f64(double %r)
432+
ret i64 %i
433+
}
434+
349435
declare i32 @llvm.fptoui.sat.i32.f16 (half)
350436
declare i64 @llvm.fptoui.sat.i64.f16 (half)
351437
declare i32 @llvm.fptoui.sat.i32.f32 (float)
@@ -357,11 +443,14 @@ declare half @llvm.floor.f16(half) nounwind readnone
357443
declare half @llvm.ceil.f16(half) nounwind readnone
358444
declare half @llvm.trunc.f16(half) nounwind readnone
359445
declare half @llvm.round.f16(half) nounwind readnone
446+
declare half @llvm.roundeven.f16(half) nounwind readnone
360447
declare float @floorf(float) nounwind readnone
361448
declare float @ceilf(float) nounwind readnone
362449
declare float @truncf(float) nounwind readnone
363450
declare float @roundf(float) nounwind readnone
451+
declare float @roundevenf(float) nounwind readnone
364452
declare double @floor(double) nounwind readnone
365453
declare double @ceil(double) nounwind readnone
366454
declare double @trunc(double) nounwind readnone
367455
declare double @round(double) nounwind readnone
456+
declare double @roundeven(double) nounwind readnone

0 commit comments

Comments
 (0)