tree-optimization: Skip debug stmts before assigning UIDs [PR127687]

Message ID 20261002033432.5848-1-yqtian668@gmail.com
State New
Headers
Series tree-optimization: Skip debug stmts before assigning UIDs [PR127687] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed

Commit Message

Yongqiang Tian Oct. 2, 2026, 3:34 a.m. UTC
  GIMPLE_DEBUG statements currently consume UIDs and are then treated as
non-assignments, which flushes pending VEC_PERM simplify sequences.  This
makes sequence blending depend on whether debug information is present.

Skip debug statements before assigning UIDs and processing ordinary
statements.

Assisted-by: OpenAI Codex 5.6 Sol, co-reviewed by Claude and Yongqiang Tian.

	PR tree-optimization/127687

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (pass_forwprop::execute): Skip debug
	statements before assigning UIDs.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr127687.c: New test.

Signed-off-by: Yongqiang Tian <yqtian668@gmail.com>
---
Tested on x86_64-pc-linux-gnu with a bootstrap and regression test.
The unexpected results were also present in the unpatched baseline; no
regressions were found.

I do not have commit access.

 gcc/testsuite/gcc.dg/pr127687.c | 23 +++++++++++++++++++++++
 gcc/tree-ssa-forwprop.cc        |  6 ++++++
 2 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/pr127687.c
  

Comments

Jakub Jelinek Oct. 2, 2026, 5:32 a.m. UTC | #1
On Fri, Oct 02, 2026 at 01:34:31PM +1000, Yongqiang Tian wrote:
> 	PR tree-optimization/127687
> 
> gcc/ChangeLog:
> 
> 	* tree-ssa-forwprop.cc (pass_forwprop::execute): Skip debug
> 	statements before assigning UIDs.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/pr127687.c: New test.
> 
> Signed-off-by: Yongqiang Tian <yqtian668@gmail.com>

> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr127687.c
> @@ -0,0 +1,23 @@
> +/* PR tree-optimization/127687 */
> +/* { dg-do compile { target aarch64*-*-* i?86-*-* x86_64-*-* } } */

I don't see any reason to limit the test just to these 3 architectures,
it should compile on any and even be useful there.
No vector argument is passed by value or returned, so there is even no
risk of extra -Wpsabi warnings, and the -fcompare-debug option ensures
on all targets that we don't emit different code based on -g vs. -g0.

> +/* { dg-options "-O2 -fcompare-debug -fdump-tree-forwprop1-details" } */
> +/* { dg-additional-options "-msse2" { target i?86-*-* x86_64-*-* } } */
> +
> +typedef int V __attribute__((vector_size (4 * sizeof (int))));
> +
> +[[gnu::noipa]] void
> +foo (V *x, V *y)
> +{
> +  V a = *x;
> +  V b = *y;
> +  V c = __builtin_shufflevector (a, a, 0, 2, 0, 2);
> +  V d = __builtin_shufflevector (a, a, 1, 3, 1, 3);
> +  V e = __builtin_shufflevector (b, b, 0, 2, 0, 2);
> +  V f = __builtin_shufflevector (b, b, 1, 3, 1, 3);
> +  V g = __builtin_shufflevector (c + d, c - d, 0, 4, 1, 5);
> +  V h = __builtin_shufflevector (e + f, e - f, 0, 4, 1, 5);
> +  *x = g;
> +  *y = h;
> +}
> +
> +/* { dg-final { scan-tree-dump "Vec perm simplify sequences have been blended" "forwprop1" } } */

I'm not sure this message will be emitted on all, so it is fine to limit
this dg-final to the above mentioned 3 architectures.

> diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
> index f341514a8..fba4387f5 100644
> --- a/gcc/tree-ssa-forwprop.cc
> +++ b/gcc/tree-ssa-forwprop.cc
> @@ -6755,6 +6755,12 @@ pass_forwprop::execute (function *fun)
>  	  tree lhs, rhs;
>  	  enum tree_code code;
>  
> +	  if (is_gimple_debug (stmt))
> +	    {
> +	      gsi_next (&gsi);
> +	      continue;
> +	    }
> +

This is certainly fine.

	Jakub
  

Patch

diff --git a/gcc/testsuite/gcc.dg/pr127687.c b/gcc/testsuite/gcc.dg/pr127687.c
new file mode 100644
index 000000000..4b30bba53
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr127687.c
@@ -0,0 +1,23 @@ 
+/* PR tree-optimization/127687 */
+/* { dg-do compile { target aarch64*-*-* i?86-*-* x86_64-*-* } } */
+/* { dg-options "-O2 -fcompare-debug -fdump-tree-forwprop1-details" } */
+/* { dg-additional-options "-msse2" { target i?86-*-* x86_64-*-* } } */
+
+typedef int V __attribute__((vector_size (4 * sizeof (int))));
+
+[[gnu::noipa]] void
+foo (V *x, V *y)
+{
+  V a = *x;
+  V b = *y;
+  V c = __builtin_shufflevector (a, a, 0, 2, 0, 2);
+  V d = __builtin_shufflevector (a, a, 1, 3, 1, 3);
+  V e = __builtin_shufflevector (b, b, 0, 2, 0, 2);
+  V f = __builtin_shufflevector (b, b, 1, 3, 1, 3);
+  V g = __builtin_shufflevector (c + d, c - d, 0, 4, 1, 5);
+  V h = __builtin_shufflevector (e + f, e - f, 0, 4, 1, 5);
+  *x = g;
+  *y = h;
+}
+
+/* { dg-final { scan-tree-dump "Vec perm simplify sequences have been blended" "forwprop1" } } */
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index f341514a8..fba4387f5 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -6755,6 +6755,12 @@  pass_forwprop::execute (function *fun)
 	  tree lhs, rhs;
 	  enum tree_code code;
 
+	  if (is_gimple_debug (stmt))
+	    {
+	      gsi_next (&gsi);
+	      continue;
+	    }
+
 	  gimple_set_uid (stmt, uid++);
 
 	  if (!is_gimple_assign (stmt))