]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[committed] [PR target/111362] Fix compare-debug issue with mode switching
authorjlaw <jeffreyalaw@gmail.com>
Sun, 10 Mar 2024 02:27:32 +0000 (19:27 -0700)
committerjlaw <jeffreyalaw@gmail.com>
Sun, 10 Mar 2024 02:39:09 +0000 (19:39 -0700)
The issue here is the code we emit for mode-switching can change when -g is
added to the command line.  This is caused by processing debug notes occurring
after a call which is the last real statement in a basic block.

Without -g the CALL_INSN is literally the last insn in the block and the loop
exits.  If mode switching after the call is needed, it'll be handled as we
process outgoing edges.

With -g the loop iterates again and in the processing of the node the backend
signals that a mode switch is necessary.

I pondered fixing this in the target, but the better fix is to ignore the debug
notes in the insn stream.

I did a cursory review of some of the other compare-debug failures, but did not
immediately see others which would likely be fixed by this change.  Sigh.

Anyway, bootstrapped and regression tested on x86.  Regression tested on rv64
as well.

PR target/111362
gcc/
* mode-switching.cc (optimize_mode_switching): Only process
NONDEBUG insns.

gcc/testsuite

* gcc.target/riscv/compare-debug-1.c: New test.
* gcc.target/riscv/compare-debug-2.c: New test.

gcc/mode-switching.cc
gcc/testsuite/gcc.target/riscv/compare-debug-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/compare-debug-2.c [new file with mode: 0644]

index 583929184ce70f0393da404633e23a0971ebd4b6..a145b77397d1215d1bbdf4a0bcc0b0b042a783cb 100644 (file)
@@ -959,7 +959,7 @@ optimize_mode_switching (void)
 
          FOR_BB_INSNS (bb, insn)
            {
-             if (INSN_P (insn))
+             if (NONDEBUG_INSN_P (insn))
                {
                  int mode = targetm.mode_switching.needed (e, insn, live_now);
                  rtx link;
diff --git a/gcc/testsuite/gcc.target/riscv/compare-debug-1.c b/gcc/testsuite/gcc.target/riscv/compare-debug-1.c
new file mode 100644 (file)
index 0000000..d65bb28
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-ch --param=max-completely-peel-times=0 -march=rv64iv -mabi=lp64d -fcompare-debug" } */
+
+
+void
+foo(void) {
+  for (unsigned i = 0; i < sizeof(foo); i++)
+    __builtin_printf("%d", i);
+}
diff --git a/gcc/testsuite/gcc.target/riscv/compare-debug-2.c b/gcc/testsuite/gcc.target/riscv/compare-debug-2.c
new file mode 100644 (file)
index 0000000..d877584
--- /dev/null
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-ch --param=max-completely-peel-times=0 -march=rv64iv -mabi=lp64d -fno-dce -fschedule-insns -fcompare-debug" } */
+#include "compare-debug-1.c"