https://gcc.gnu.org/g:8a61f5a39896d4c91acfd34a339f562a946769b4

commit r17-6408-g8a61f5a39896d4c91acfd34a339f562a946769b4
Author: Sebastian Huber <[email protected]>
Date:   Tue Nov 17 13:17:54 2026 +0100

    sparc: Skip empty insns at errata branch targets
    
    The GR712RC workaround for GRLIB-TN-0012 missed a floating-point
    operation at the target of an integer branch if the epilogue started at
    the target.  The zero-length frame blockage of the epilogue was the next
    active insn after the label, so no NOP was inserted before the
    floating-point operation.  Newlib ceilf() and floorf() compiled with
    -mcpu=leon3 -mfix-gr712rc -O2 contained such a sequence.  The UT700
    check for an atomic instruction at a branch target used the same lookup.
    
    Use next_active_non_empty_insn() to find the instruction at the branch
    target.
    
    Assisted-by: Claude Opus 5.5
    
    gcc/ChangeLog:
    
            * config/sparc/sparc.cc (sparc_do_work_around_errata): Use
            next_active_non_empty_insn to find the insn at a branch target.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/sparc/fix-gr712rc-1.c: New test.
    
    Signed-off-by: Sebastian Huber <[email protected]>

Diff:
---
 gcc/config/sparc/sparc.cc                      |  6 ++++--
 gcc/testsuite/gcc.target/sparc/fix-gr712rc-1.c | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc
index e69d7625310c..4477b0632c5e 100644
--- a/gcc/config/sparc/sparc.cc
+++ b/gcc/config/sparc/sparc.cc
@@ -1190,7 +1190,8 @@ sparc_do_work_around_errata (void)
          && jump_to_label_p (jump)
          && get_attr_branch_type (jump) == BRANCH_TYPE_ICC)
        {
-         rtx_insn *target = next_active_insn (JUMP_LABEL_AS_INSN (jump));
+         rtx_insn *target
+           = next_active_non_empty_insn (JUMP_LABEL_AS_INSN (jump));
          if (target
              && (fpop_insn_p (target)
                  || (JUMP_P (target)
@@ -1207,7 +1208,8 @@ sparc_do_work_around_errata (void)
        {
          if (jump && jump_to_label_p (jump))
            {
-             rtx_insn *target = next_active_insn (JUMP_LABEL_AS_INSN (jump));
+             rtx_insn *target
+               = next_active_non_empty_insn (JUMP_LABEL_AS_INSN (jump));
              if (target && atomic_insn_for_leon3_p (target))
                emit_insn_before (gen_nop (), target);
            }
diff --git a/gcc/testsuite/gcc.target/sparc/fix-gr712rc-1.c 
b/gcc/testsuite/gcc.target/sparc/fix-gr712rc-1.c
new file mode 100644
index 000000000000..f7c6a071cad2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/sparc/fix-gr712rc-1.c
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target ilp32 } */
+/* { dg-skip-if "no FPU" { *-*-* } { "-msoft-float" } { "" } } */
+/* { dg-options "-mcpu=leon3 -mfix-gr712rc -O2" } */
+
+/* GRLIB-TN-0012: a floating-point operation at the target of an integer
+   branch needs a NOP before it, also where the epilogue starts at the
+   branch target.  */
+
+int a, b;
+
+float
+foo (float x)
+{
+  union { float f; int i; } u;
+
+  u.f = x;
+  a = u.i;
+  if (u.i && b)
+    return x + x;
+  return x;
+}
+
+/* { dg-final { scan-assembler "nop\n\tfadds" } } */
+/* { dg-final { scan-assembler-not ":\n\tfadds" } } */

Reply via email to