https://gcc.gnu.org/g:c66712b7c5453c202ef72881b594436163d03552
commit r17-6568-gc66712b7c5453c202ef72881b594436163d03552 Author: Sebastian Huber <[email protected]> Date: Fri Nov 20 00:59:49 2026 +0100 sparc: Skip empty insns in errata insn windows The workarounds for the lost FDIV or FSQRT result, for the AT697F and for the UT699 used next_active_insn() to walk their instruction windows. A zero-length insn, such as the frame blockage or an empty asm statement, emits no instruction, but it took a place in the window. A problematic sequence which spanned such an insn got no NOP. Use next_active_non_empty_insn() in these walks, like the workarounds for the branch target, the UT700 and the back-to-back stores. Assisted-by: Claude Opus 5.5 Co-authored-by: Matteo Concas <[email protected]> gcc/ChangeLog: * config/sparc/sparc.cc (sparc_do_work_around_errata): Use next_active_non_empty_insn to walk the instruction windows of the lost divide/square root, the AT697F and the UT699 workarounds. gcc/testsuite/ChangeLog: * gcc.target/sparc/fix-gr712rc-1.c: Add lost divide tests. * gcc.target/sparc/fix-at697f-1.c: New test. * gcc.target/sparc/fix-ut699-1.c: New test. Signed-off-by: Sebastian Huber <[email protected]> Diff: --- gcc/config/sparc/sparc.cc | 12 +++---- gcc/testsuite/gcc.target/sparc/fix-at697f-1.c | 22 +++++++++++++ gcc/testsuite/gcc.target/sparc/fix-gr712rc-1.c | 36 +++++++++++++++++++++ gcc/testsuite/gcc.target/sparc/fix-ut699-1.c | 45 ++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 6 deletions(-) diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc index 93327f09d15a..ca2994e0fd78 100644 --- a/gcc/config/sparc/sparc.cc +++ b/gcc/config/sparc/sparc.cc @@ -1235,7 +1235,7 @@ sparc_do_work_around_errata (void) const unsigned int dest_reg = REGNO (SET_DEST (single_set (insn))); - next = next_active_insn (insn); + next = next_active_non_empty_insn (insn); if (!next) break; @@ -1291,7 +1291,7 @@ sparc_do_work_around_errata (void) break; } - after = next_active_insn (after); + after = next_active_non_empty_insn (after); if (!after) break; } @@ -1374,7 +1374,7 @@ sparc_do_work_around_errata (void) unsigned int src1, src2, dest; int code; - next = next_active_insn (insn); + next = next_active_non_empty_insn (insn); if (!next) break; /* If the insn is a branch, then it cannot be problematic. */ @@ -1443,7 +1443,7 @@ sparc_do_work_around_errata (void) dependency on the first single-cycle load. */ rtx x = SET_DEST (set); - next = next_active_insn (insn); + next = next_active_non_empty_insn (insn); if (!next) break; /* If the insn is a branch, then it cannot be problematic. */ @@ -1497,7 +1497,7 @@ sparc_do_work_around_errata (void) rtx_insn *after; int i; - next = next_active_insn (insn); + next = next_active_non_empty_insn (insn); if (!next) break; /* If the insn is a branch, then it cannot be problematic. */ @@ -1518,7 +1518,7 @@ sparc_do_work_around_errata (void) { bool branch_p; - after = next_active_insn (after); + after = next_active_non_empty_insn (after); if (!after) break; diff --git a/gcc/testsuite/gcc.target/sparc/fix-at697f-1.c b/gcc/testsuite/gcc.target/sparc/fix-at697f-1.c new file mode 100644 index 000000000000..798ea383b7a2 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/fix-at697f-1.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target ilp32 } */ +/* { dg-skip-if "no FPU" { *-*-* } { "-msoft-float" } { "" } } */ +/* { dg-options "-mcpu=leon -mfix-at697f -O2" } */ + +/* AT697F: a single-word load into an odd-numbered FP register followed by + a double-precision operation on the enclosing register needs a NOP in + between. An empty asm statement emits no instruction, so it does not + separate the two instructions. */ + +double +foo (double x, const float *p) +{ + union { double d; float f[2]; } u; + + u.d = x; + u.f[1] = *p; + __asm__ volatile ("" : : : "memory"); + return u.d + u.d; +} + +/* { dg-final { scan-assembler "ld\t\[^\n\]*%f\[0-9\]*\[13579\]\n\tnop\n\tfaddd" } } */ diff --git a/gcc/testsuite/gcc.target/sparc/fix-gr712rc-1.c b/gcc/testsuite/gcc.target/sparc/fix-gr712rc-1.c index f7c6a071cad2..ec974364d4ff 100644 --- a/gcc/testsuite/gcc.target/sparc/fix-gr712rc-1.c +++ b/gcc/testsuite/gcc.target/sparc/fix-gr712rc-1.c @@ -21,5 +21,41 @@ foo (float x) return x; } +/* The workaround for the lost FDIV or FSQRT result inserts two NOPs after + the first division of the short sequence FDIVD, FADDD, FADDD, FDIVD. An + empty asm statement emits no instruction, so it does not count as an + instruction of the sequence. */ + +void +div_first (const double *p) +{ + double a = p[0], b = p[1], c = p[2], d = p[3]; + double e = p[4], f = p[5], g = p[6], h = p[7]; + __asm__ volatile ("" : : "e" (a), "e" (b), "e" (c), "e" (d), + "e" (e), "e" (f), "e" (g), "e" (h)); + double x = a / b; + __asm__ volatile ("" : : "e" (x)); + double y = c + d; + double z = e + f; + double w = g / h; + __asm__ volatile ("" : : "e" (x), "e" (y), "e" (z), "e" (w)); +} + +void +div_window (const double *p) +{ + double a = p[0], b = p[1], c = p[2], d = p[3]; + double e = p[4], f = p[5], g = p[6], h = p[7]; + __asm__ volatile ("" : : "e" (a), "e" (b), "e" (c), "e" (d), + "e" (e), "e" (f), "e" (g), "e" (h)); + double x = a / b; + double y = c + d; + __asm__ volatile ("" : : "e" (x), "e" (y)); + double z = e + f; + double w = g / h; + __asm__ volatile ("" : : "e" (x), "e" (y), "e" (z), "e" (w)); +} + +/* { dg-final { scan-assembler-times "fdivd\t\[^\n\]*\n\tnop\n\tnop\n\tfaddd" 2 } } */ /* { dg-final { scan-assembler "nop\n\tfadds" } } */ /* { dg-final { scan-assembler-not ":\n\tfadds" } } */ diff --git a/gcc/testsuite/gcc.target/sparc/fix-ut699-1.c b/gcc/testsuite/gcc.target/sparc/fix-ut699-1.c new file mode 100644 index 000000000000..6ef0ebbe42c3 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/fix-ut699-1.c @@ -0,0 +1,45 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target ilp32 } */ +/* { dg-skip-if "no FPU" { *-*-* } { "-msoft-float" } { "" } } */ +/* { dg-options "-mcpu=leon3 -mfix-ut699 -O2" } */ + +/* UT699: two back-to-back loads need a NOP in between. An empty asm + statement emits no instruction, so it does not separate the two loads. */ + +int +load_int (const int *p, const int *q) +{ + int a = *p; + __asm__ volatile ("" : : : "memory"); + int b = *q; + return a + b; +} + +/* UT699: a single-word load into an FP register, a load into its sibling + register and a store of the first register within the next four + instructions need a NOP after the first load. */ + +void +load_fp_first (const float *p, float *r) +{ + float x = p[0]; + __asm__ volatile ("" : : : "memory"); + float y = p[1]; + r[0] = x; + r[1] = y; +} + +void +load_fp_window (const float *p, float *r) +{ + float x = p[0]; + float y = p[1]; + __asm__ volatile ("" : : : "memory"); + __asm__ volatile ("" : : : "memory"); + __asm__ volatile ("" : : : "memory"); + __asm__ volatile ("" : : : "memory"); + r[0] = x; + r[1] = y; +} + +/* { dg-final { scan-assembler-times "ld\t\[^\n\]*\n\tnop\n\tld\t" 3 } } */
