]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
SLSR: Wrong type sometimes for rhs2 with pointers [PR123803]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 24 Jan 2026 07:13:25 +0000 (23:13 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 24 Jan 2026 17:50:17 +0000 (09:50 -0800)
I messed up one of the new gimple_convert when there is
still a pointer type (with -fwrapv-pointer or -fno-strict-overflow).
The newrhs2 should be converted into sizetype instead of the type
of the lhs. Other places were already done correctly, it was
just in replace_rhs_if_not_dup which was broken this way.

Pushed as obvious after bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/123803

gcc/ChangeLog:

* gimple-ssa-strength-reduction.cc (replace_rhs_if_not_dup): For
pointer lhs use sizetype.

gcc/testsuite/ChangeLog:

* gcc.dg/pr123803-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/gimple-ssa-strength-reduction.cc
gcc/testsuite/gcc.dg/pr123803-1.c [new file with mode: 0644]

index d493dc87d3a5ea8eb9c859fc3dcd8d7e784edb76..f3571e10e90d65465ea061b6eea20457096ec52f 100644 (file)
@@ -3711,12 +3711,15 @@ replace_rhs_if_not_dup (enum tree_code new_code, tree new_rhs1, tree new_rhs2,
     {
       tree lhs = gimple_assign_lhs (c->cand_stmt);
       gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt);
+      tree rhs2_type = TREE_TYPE (lhs);
+      if (POINTER_TYPE_P (rhs2_type))
+       rhs2_type = sizetype;
       new_rhs1 = gimple_convert (&gsi, true, GSI_SAME_STMT,
                                 UNKNOWN_LOCATION,
                                 TREE_TYPE (lhs), new_rhs1);
       new_rhs2 = gimple_convert (&gsi, true, GSI_SAME_STMT,
                                 UNKNOWN_LOCATION,
-                                TREE_TYPE (lhs), new_rhs2);
+                                rhs2_type, new_rhs2);
       slsr_cand_t cc = lookup_cand (c->first_interp);
       gimple_assign_set_rhs_with_ops (&gsi, new_code, new_rhs1, new_rhs2);
       update_stmt (gsi_stmt (gsi));
diff --git a/gcc/testsuite/gcc.dg/pr123803-1.c b/gcc/testsuite/gcc.dg/pr123803-1.c
new file mode 100644 (file)
index 0000000..81c2356
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-strict-overflow" } */
+/* PR tree-optimization/123803 */
+
+/* SLSR with wrapping pointers converted the new
+   nhs2 into the pointer type instead of sizetype. */
+int f(int *x1,__SIZE_TYPE__ n) {
+  return *(x1 + n) +
+  *(x1 + 3 * n);
+}