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 <[email protected]>
---
 gcc/gimple-ssa-strength-reduction.cc      |  5 +--
 gcc/testsuite/g++.dg/torture/pr123820-1.C | 41 +++++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr123820-1.C

diff --git a/gcc/gimple-ssa-strength-reduction.cc 
b/gcc/gimple-ssa-strength-reduction.cc
index f3571e10e90..ced2235498c 100644
--- a/gcc/gimple-ssa-strength-reduction.cc
+++ b/gcc/gimple-ssa-strength-reduction.cc
@@ -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
index 00000000000..3c9d1f0127a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr123820-1.C
@@ -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;
+}
+
-- 
2.43.0

Reply via email to