]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
slsr: Use the correct type to try to convert to for inserting on edge case [PR123820]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 26 Jan 2026 06:23:51 +0000 (22:23 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 26 Jan 2026 19:10:57 +0000 (11:10 -0800)
I had noticed there was code that will convert the stride
to the correct type
What I didn't realize was the type which it was trying to
use was stride_type but for this case it should have been using
the type of the lhs. This fixes that oversight. Note for pointers
we still want to use stride_type like what is done right above.

I don't have a testcase that does not use LTO though. I didn't figure
out why this testcase needed LTO though.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/123820

gcc/ChangeLog:

* gimple-ssa-strength-reduction.cc (create_add_on_incoming_edge): Use
the correct type for the stride (lhs if non-pointer).

gcc/testsuite/ChangeLog:

* g++.dg/torture/pr123820-1.C: New test.

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

index f3571e10e90d65465ea061b6eea20457096ec52f..ced2235498cb4566a351222d6f728392b8a0ca0e 100644 (file)
@@ -2356,10 +2356,11 @@ create_add_on_incoming_edge (slsr_cand_t c, tree basis_name,
        }
       else {
        tree stride;
+       tree wanted_type = POINTER_TYPE_P (basis_type) ? c->stride_type : basis_type;
 
-       if (!types_compatible_p (TREE_TYPE (c->stride), c->stride_type))
+       if (!types_compatible_p (TREE_TYPE (c->stride), wanted_type))
          {
-           tree cast_stride = make_temp_ssa_name (c->stride_type, NULL,
+           tree cast_stride = make_temp_ssa_name (wanted_type, NULL,
                                                   "slsr");
            cast_stmt = gimple_build_assign (cast_stride, NOP_EXPR,
                                             c->stride);
diff --git a/gcc/testsuite/g++.dg/torture/pr123820-1.C b/gcc/testsuite/g++.dg/torture/pr123820-1.C
new file mode 100644 (file)
index 0000000..3c9d1f0
--- /dev/null
@@ -0,0 +1,41 @@
+/* { dg-do run } */
+/* PR tree-optimization/123820 */
+
+struct Trit { char value; };
+
+struct Matrix {
+    int width;
+    Trit* data;
+
+    Trit& at(int x, int y) {
+        if (!(x >= y)) __builtin_abort ();
+        return data[y * width];
+    }
+};
+
+
+Trit set_value;
+[[gnu::used]]
+int EmbedPositionDetectionPattern_yStart;
+
+[[gnu::used,gnu::noipa]]
+void EmbedPositionDetectionPattern(Matrix& m) {
+    for (int y = 0; y < 7; ++y)
+        for (int x = 0; x < 7; ++x)
+            m.at(x, EmbedPositionDetectionPattern_yStart + y) = {0};
+
+    for (int i = 1; i < 8; ++i) {
+        if (i < m.width)
+            m.at(i, 7) = {0};
+
+        int y = EmbedPositionDetectionPattern_yStart + i;
+        if (7 < m.width && y)
+            m.at(7, y) = {0};
+    }
+}
+
+int main()
+{
+  return 0;
+}
+