]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix ICE in loop splitting with -fno-guess-branch-probability
authorJan Hubicka <jh@suse.cz>
Wed, 14 Feb 2024 16:37:34 +0000 (17:37 +0100)
committerJan Hubicka <jh@suse.cz>
Wed, 14 Feb 2024 16:37:34 +0000 (17:37 +0100)
PR tree-optimization/111054

gcc/ChangeLog:

* tree-ssa-loop-split.cc (split_loop): Check for profile being present.

gcc/testsuite/ChangeLog:

* gcc.c-torture/compile/pr111054.c: New test.

gcc/testsuite/gcc.c-torture/compile/pr111054.c [new file with mode: 0644]
gcc/tree-ssa-loop-split.cc

diff --git a/gcc/testsuite/gcc.c-torture/compile/pr111054.c b/gcc/testsuite/gcc.c-torture/compile/pr111054.c
new file mode 100644 (file)
index 0000000..3c0d6e8
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-additional-options "-fno-guess-branch-probability" } */
+void *p, *q;
+int i, j;
+
+void
+foo (void)
+{
+  for (i = 0; i < 20; i++)
+    if (i < j)
+      p = q;
+}
index 04215fe7937ea9885da42f388a7e77862958b84e..c0bb1b71d17cefc272e516b1433911d1b016a9e9 100644 (file)
@@ -712,7 +712,8 @@ split_loop (class loop *loop1)
                          ? true_edge->probability.to_sreal () : (sreal)1;
            sreal scale2 = false_edge->probability.reliable_p ()
                          ? false_edge->probability.to_sreal () : (sreal)1;
-           sreal div1 = loop1_prob.to_sreal ();
+           sreal div1 = loop1_prob.initialized_p ()
+                        ? loop1_prob.to_sreal () : (sreal)1/(sreal)2;
            /* +1 to get header interations rather than latch iterations and then
               -1 to convert back.  */
            if (div1 != 0)