]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/107493 - SCEV analysis with conversions
authorRichard Biener <rguenther@suse.de>
Mon, 28 Nov 2022 09:25:44 +0000 (10:25 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 28 Nov 2022 10:17:03 +0000 (11:17 +0100)
This shows another case where trying to validate conversions during
the CHREC SCC analysis fails because said analysis assumes we are
converting a complete SCC.  Like the constraint on the initial
conversion seen restrict all conversions handled to sign-changes.

PR tree-optimization/107493
* tree-scalar-evolution.cc (scev_dfs::follow_ssa_edge_expr):
Only handle no-op and sign-changing conversions.

* gcc.dg/torture/pr107493.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr107493.c [new file with mode: 0644]
gcc/tree-scalar-evolution.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr107493.c b/gcc/testsuite/gcc.dg/torture/pr107493.c
new file mode 100644 (file)
index 0000000..b366921
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do run { target int32plus } } */
+
+int a;
+int b(int c) { return c; }
+int main()
+{
+  a = -21;
+  for (; a <= 0; a = (unsigned short)(b(a + 2) + 8))
+    ;
+  if (a != 65525)
+    __builtin_abort();
+  return 0;
+}
index 60060337804aebd4538ec90057c219fab9acf63a..f75398afb7c9fdf42e69e940e2232942143049f6 100644 (file)
@@ -1227,10 +1227,16 @@ scev_dfs::follow_ssa_edge_expr (gimple *at_stmt, tree expr,
     {
     CASE_CONVERT:
       {
-       /* This assignment is under the form "a_1 = (cast) rhs.  */
+       /* This assignment is under the form "a_1 = (cast) rhs.  We cannot
+          validate any precision altering conversion during the SCC
+          analysis, so don't even try.  */
+       if (!tree_nop_conversion_p (type, TREE_TYPE (rhs0)))
+         return t_false;
        t_bool res = follow_ssa_edge_expr (at_stmt, rhs0,
                                           evolution_of_loop, limit);
-       *evolution_of_loop = chrec_convert (type, *evolution_of_loop, at_stmt);
+       if (res == t_true)
+         *evolution_of_loop = chrec_convert (type, *evolution_of_loop,
+                                             at_stmt);
        return res;
       }