Skip to content

Commit 549d7c4

Browse files
authored
[SPARC] Change half to use soft promotion rather than PromoteFloat (#152727)
`half` currently uses the default legalization of promoting to a `f32`; however, this implementation implements math in a way that results in incorrect rounding. Switch to the soft promote implementation, which does not have this problem. The SPARC ABI does not specify a `_Float16` type, so there is no concern with keeping interface compatibility. Fixes the SPARC part of #97975 Fixes the SPARC part of #97981
1 parent 43df97a commit 549d7c4

File tree

5 files changed

+289
-351
lines changed

5 files changed

+289
-351
lines changed

llvm/lib/Target/Sparc/SparcISelLowering.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace llvm {
2828

2929
bool useSoftFloat() const override;
3030

31+
bool softPromoteHalfType() const override { return true; }
32+
3133
/// computeKnownBitsForTargetNode - Determine which of the bits specified
3234
/// in Mask are known to be either zero or one and return them in the
3335
/// KnownZero/KnownOne bitsets.

llvm/test/CodeGen/Generic/half.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
; RUN: %if powerpc-registered-target %{ llc %s -o - -mtriple=powerpc64le-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD %}
3535
; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
3636
; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
37-
; RUN: %if sparc-registered-target %{ llc %s -o - -mtriple=sparc-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD %}
38-
; RUN: %if sparc-registered-target %{ llc %s -o - -mtriple=sparc64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD %}
37+
; RUN: %if sparc-registered-target %{ llc %s -o - -mtriple=sparc-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
38+
; RUN: %if sparc-registered-target %{ llc %s -o - -mtriple=sparc64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
3939
; RUN: %if spirv-registered-target %{ llc %s -o - -mtriple=spirv-unknown-unknown | FileCheck %s --check-prefixes=NOCRASH %}
4040
; RUN: %if systemz-registered-target %{ llc %s -o - -mtriple=s390x-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
4141
; RUN: %if ve-registered-target %{ llc %s -o - -mtriple=ve-unknown-unknown | FileCheck %s --check-prefixes=ALL,BAD %}

llvm/test/CodeGen/SPARC/fp16-promote.ll

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,14 @@ define void @test_fadd(ptr %p, ptr %q) nounwind {
329329
; V8-OPT-LABEL: test_fadd:
330330
; V8-OPT: ! %bb.0:
331331
; V8-OPT-NEXT: save %sp, -104, %sp
332+
; V8-OPT-NEXT: lduh [%i0], %i2
332333
; V8-OPT-NEXT: call __extendhfsf2
333-
; V8-OPT-NEXT: lduh [%i0], %o0
334+
; V8-OPT-NEXT: lduh [%i1], %o0
334335
; V8-OPT-NEXT: st %f0, [%fp+-8] ! 4-byte Folded Spill
335336
; V8-OPT-NEXT: call __extendhfsf2
336-
; V8-OPT-NEXT: lduh [%i1], %o0
337+
; V8-OPT-NEXT: mov %i2, %o0
337338
; V8-OPT-NEXT: ld [%fp+-8], %f1 ! 4-byte Folded Reload
338-
; V8-OPT-NEXT: fadds %f1, %f0, %f0
339+
; V8-OPT-NEXT: fadds %f0, %f1, %f0
339340
; V8-OPT-NEXT: st %f0, [%fp+-4]
340341
; V8-OPT-NEXT: call __truncsfhf2
341342
; V8-OPT-NEXT: ld [%fp+-4], %o0
@@ -346,13 +347,14 @@ define void @test_fadd(ptr %p, ptr %q) nounwind {
346347
; V8-UNOPT-LABEL: test_fadd:
347348
; V8-UNOPT: ! %bb.0:
348349
; V8-UNOPT-NEXT: save %sp, -104, %sp
349-
; V8-UNOPT-NEXT: call __extendhfsf2
350-
; V8-UNOPT-NEXT: lduh [%i0], %o0
351-
; V8-UNOPT-NEXT: st %f0, [%fp+-8] ! 4-byte Folded Spill
350+
; V8-UNOPT-NEXT: lduh [%i0], %i2
351+
; V8-UNOPT-NEXT: st %i2, [%fp+-12] ! 4-byte Folded Spill
352352
; V8-UNOPT-NEXT: call __extendhfsf2
353353
; V8-UNOPT-NEXT: lduh [%i1], %o0
354-
; V8-UNOPT-NEXT: fmovs %f0, %f1
355-
; V8-UNOPT-NEXT: ld [%fp+-8], %f0 ! 4-byte Folded Reload
354+
; V8-UNOPT-NEXT: ld [%fp+-12], %o0 ! 4-byte Folded Reload
355+
; V8-UNOPT-NEXT: call __extendhfsf2
356+
; V8-UNOPT-NEXT: st %f0, [%fp+-8]
357+
; V8-UNOPT-NEXT: ld [%fp+-8], %f1 ! 4-byte Folded Reload
356358
; V8-UNOPT-NEXT: fadds %f0, %f1, %f0
357359
; V8-UNOPT-NEXT: st %f0, [%fp+-4]
358360
; V8-UNOPT-NEXT: call __truncsfhf2
@@ -364,13 +366,14 @@ define void @test_fadd(ptr %p, ptr %q) nounwind {
364366
; V9-LABEL: test_fadd:
365367
; V9: ! %bb.0:
366368
; V9-NEXT: save %sp, -104, %sp
369+
; V9-NEXT: lduh [%i0], %i2
367370
; V9-NEXT: call __extendhfsf2
368-
; V9-NEXT: lduh [%i0], %o0
371+
; V9-NEXT: lduh [%i1], %o0
369372
; V9-NEXT: st %f0, [%fp+-8] ! 4-byte Folded Spill
370373
; V9-NEXT: call __extendhfsf2
371-
; V9-NEXT: lduh [%i1], %o0
374+
; V9-NEXT: mov %i2, %o0
372375
; V9-NEXT: ld [%fp+-8], %f1 ! 4-byte Folded Reload
373-
; V9-NEXT: fadds %f1, %f0, %f0
376+
; V9-NEXT: fadds %f0, %f1, %f0
374377
; V9-NEXT: st %f0, [%fp+-4]
375378
; V9-NEXT: call __truncsfhf2
376379
; V9-NEXT: ld [%fp+-4], %o0
@@ -381,14 +384,15 @@ define void @test_fadd(ptr %p, ptr %q) nounwind {
381384
; SPARC64-LABEL: test_fadd:
382385
; SPARC64: ! %bb.0:
383386
; SPARC64-NEXT: save %sp, -192, %sp
387+
; SPARC64-NEXT: lduh [%i0], %i2
384388
; SPARC64-NEXT: call __extendhfsf2
385-
; SPARC64-NEXT: lduh [%i0], %o0
389+
; SPARC64-NEXT: lduh [%i1], %o0
386390
; SPARC64-NEXT: st %f0, [%fp+2043] ! 4-byte Folded Spill
387391
; SPARC64-NEXT: call __extendhfsf2
388-
; SPARC64-NEXT: lduh [%i1], %o0
392+
; SPARC64-NEXT: mov %i2, %o0
389393
; SPARC64-NEXT: ld [%fp+2043], %f1 ! 4-byte Folded Reload
390394
; SPARC64-NEXT: call __truncsfhf2
391-
; SPARC64-NEXT: fadds %f1, %f0, %f1
395+
; SPARC64-NEXT: fadds %f0, %f1, %f1
392396
; SPARC64-NEXT: sth %o0, [%i0]
393397
; SPARC64-NEXT: ret
394398
; SPARC64-NEXT: restore
@@ -403,13 +407,14 @@ define void @test_fmul(ptr %p, ptr %q) nounwind {
403407
; V8-OPT-LABEL: test_fmul:
404408
; V8-OPT: ! %bb.0:
405409
; V8-OPT-NEXT: save %sp, -104, %sp
410+
; V8-OPT-NEXT: lduh [%i0], %i2
406411
; V8-OPT-NEXT: call __extendhfsf2
407-
; V8-OPT-NEXT: lduh [%i0], %o0
412+
; V8-OPT-NEXT: lduh [%i1], %o0
408413
; V8-OPT-NEXT: st %f0, [%fp+-8] ! 4-byte Folded Spill
409414
; V8-OPT-NEXT: call __extendhfsf2
410-
; V8-OPT-NEXT: lduh [%i1], %o0
415+
; V8-OPT-NEXT: mov %i2, %o0
411416
; V8-OPT-NEXT: ld [%fp+-8], %f1 ! 4-byte Folded Reload
412-
; V8-OPT-NEXT: fmuls %f1, %f0, %f0
417+
; V8-OPT-NEXT: fmuls %f0, %f1, %f0
413418
; V8-OPT-NEXT: st %f0, [%fp+-4]
414419
; V8-OPT-NEXT: call __truncsfhf2
415420
; V8-OPT-NEXT: ld [%fp+-4], %o0
@@ -420,13 +425,14 @@ define void @test_fmul(ptr %p, ptr %q) nounwind {
420425
; V8-UNOPT-LABEL: test_fmul:
421426
; V8-UNOPT: ! %bb.0:
422427
; V8-UNOPT-NEXT: save %sp, -104, %sp
423-
; V8-UNOPT-NEXT: call __extendhfsf2
424-
; V8-UNOPT-NEXT: lduh [%i0], %o0
425-
; V8-UNOPT-NEXT: st %f0, [%fp+-8] ! 4-byte Folded Spill
428+
; V8-UNOPT-NEXT: lduh [%i0], %i2
429+
; V8-UNOPT-NEXT: st %i2, [%fp+-12] ! 4-byte Folded Spill
426430
; V8-UNOPT-NEXT: call __extendhfsf2
427431
; V8-UNOPT-NEXT: lduh [%i1], %o0
428-
; V8-UNOPT-NEXT: fmovs %f0, %f1
429-
; V8-UNOPT-NEXT: ld [%fp+-8], %f0 ! 4-byte Folded Reload
432+
; V8-UNOPT-NEXT: ld [%fp+-12], %o0 ! 4-byte Folded Reload
433+
; V8-UNOPT-NEXT: call __extendhfsf2
434+
; V8-UNOPT-NEXT: st %f0, [%fp+-8]
435+
; V8-UNOPT-NEXT: ld [%fp+-8], %f1 ! 4-byte Folded Reload
430436
; V8-UNOPT-NEXT: fmuls %f0, %f1, %f0
431437
; V8-UNOPT-NEXT: st %f0, [%fp+-4]
432438
; V8-UNOPT-NEXT: call __truncsfhf2
@@ -438,13 +444,14 @@ define void @test_fmul(ptr %p, ptr %q) nounwind {
438444
; V9-LABEL: test_fmul:
439445
; V9: ! %bb.0:
440446
; V9-NEXT: save %sp, -104, %sp
447+
; V9-NEXT: lduh [%i0], %i2
441448
; V9-NEXT: call __extendhfsf2
442-
; V9-NEXT: lduh [%i0], %o0
449+
; V9-NEXT: lduh [%i1], %o0
443450
; V9-NEXT: st %f0, [%fp+-8] ! 4-byte Folded Spill
444451
; V9-NEXT: call __extendhfsf2
445-
; V9-NEXT: lduh [%i1], %o0
452+
; V9-NEXT: mov %i2, %o0
446453
; V9-NEXT: ld [%fp+-8], %f1 ! 4-byte Folded Reload
447-
; V9-NEXT: fmuls %f1, %f0, %f0
454+
; V9-NEXT: fmuls %f0, %f1, %f0
448455
; V9-NEXT: st %f0, [%fp+-4]
449456
; V9-NEXT: call __truncsfhf2
450457
; V9-NEXT: ld [%fp+-4], %o0
@@ -455,14 +462,15 @@ define void @test_fmul(ptr %p, ptr %q) nounwind {
455462
; SPARC64-LABEL: test_fmul:
456463
; SPARC64: ! %bb.0:
457464
; SPARC64-NEXT: save %sp, -192, %sp
465+
; SPARC64-NEXT: lduh [%i0], %i2
458466
; SPARC64-NEXT: call __extendhfsf2
459-
; SPARC64-NEXT: lduh [%i0], %o0
467+
; SPARC64-NEXT: lduh [%i1], %o0
460468
; SPARC64-NEXT: st %f0, [%fp+2043] ! 4-byte Folded Spill
461469
; SPARC64-NEXT: call __extendhfsf2
462-
; SPARC64-NEXT: lduh [%i1], %o0
470+
; SPARC64-NEXT: mov %i2, %o0
463471
; SPARC64-NEXT: ld [%fp+2043], %f1 ! 4-byte Folded Reload
464472
; SPARC64-NEXT: call __truncsfhf2
465-
; SPARC64-NEXT: fmuls %f1, %f0, %f1
473+
; SPARC64-NEXT: fmuls %f0, %f1, %f1
466474
; SPARC64-NEXT: sth %o0, [%i0]
467475
; SPARC64-NEXT: ret
468476
; SPARC64-NEXT: restore

0 commit comments

Comments
 (0)