The CFI output for when we do stack probing in a loop were not
accounting for the first sp adjustments, we can fix that by using the
frame's total size.
This is already being tested by g++.dg/torture/pr119610.C.

gcc/ChangeLog:
        gcc/config/riscv/riscv.cc
        (riscv_allocate_and_probe_stack_space): Use the total frame size
        instead of the current adjustment size to set the CFI.

gcc/testsuite/ChangeLog:
        gcc.target/riscv/stack-check-cfa-2.c: Fix expected output.
---
 gcc/config/riscv/riscv.cc                          | 5 +++--
 gcc/testsuite/gcc.target/riscv/stack-check-cfa-2.c | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index bbc7547d385..3e31438c50c 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -8977,12 +8977,13 @@ riscv_allocate_and_probe_stack_space (rtx temp1, 
HOST_WIDE_INT size)
       temp2 = riscv_force_temporary (temp2, gen_int_mode (rounded_size, 
Pmode));
       insn = emit_insn (gen_sub3_insn (temp2, stack_pointer_rtx, temp2));
 
+      auto cfa_offset = cfun->machine->frame.total_size;
       if (!frame_pointer_needed)
        {
          /* We want the CFA independent of the stack pointer for the
             duration of the loop.  */
          add_reg_note (insn, REG_CFA_DEF_CFA,
-                       plus_constant (Pmode, temp1, rounded_size));
+                       plus_constant (Pmode, temp1, cfa_offset));
          RTX_FRAME_RELATED_P (insn) = 1;
        }
 
@@ -8995,7 +8996,7 @@ riscv_allocate_and_probe_stack_space (rtx temp1, 
HOST_WIDE_INT size)
        {
          insn = get_last_insn ();
          add_reg_note (insn, REG_CFA_DEF_CFA,
-                       plus_constant (Pmode, stack_pointer_rtx, rounded_size));
+                       plus_constant (Pmode, stack_pointer_rtx, cfa_offset));
          RTX_FRAME_RELATED_P (insn) = 1;
        }
 
diff --git a/gcc/testsuite/gcc.target/riscv/stack-check-cfa-2.c 
b/gcc/testsuite/gcc.target/riscv/stack-check-cfa-2.c
index 9d36a302222..3649bd1a9ce 100644
--- a/gcc/testsuite/gcc.target/riscv/stack-check-cfa-2.c
+++ b/gcc/testsuite/gcc.target/riscv/stack-check-cfa-2.c
@@ -5,9 +5,9 @@
 #define SIZE 80*1024 + 512
 #include "stack-check-prologue.h"
 
-/* { dg-final { scan-assembler-times {\.cfi_def_cfa [0-9]+, 81920} 1 } } */
+/* { dg-final { scan-assembler-times {\.cfi_def_cfa [0-9]+, 82432} 1 } } */
 /* { dg-final { scan-assembler-times {\.cfi_def_cfa_register 2} 1 } } */
-/* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 82432} 1 } } */
+/* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 82944} 1 } } */
 /* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 0} 1 } } */
 
 /* Checks that the CFA notes are correct for every sp adjustment.  */
-- 
2.47.0

Reply via email to