aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gfortran.dg/pr25623-2.f9019
-rw-r--r--gcc/tree-ssa-loop-ch.cc2
-rw-r--r--gcc/tree-ssa-loop-ivcanon.cc6
3 files changed, 27 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/pr25623-2.f90 b/gcc/testsuite/gfortran.dg/pr25623-2.f90
new file mode 100644
index 0000000..57679e0
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr25623-2.f90
@@ -0,0 +1,19 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-optimized-blocks -O3" }
+
+SUBROUTINE S42(a,b,c,N)
+ IMPLICIT NONE
+ integer :: N
+ real*8 :: a(N),b(N),c(N),tmp,tmp2,tmp4
+ real*8, parameter :: p=1.0D0/3.0D0
+ integer :: i
+ c=0.0D0
+ DO i=1,N
+ tmp=a(i)**p ! could even be done with a cube root
+ tmp2=tmp*tmp
+ tmp4=tmp2*tmp2
+ b(i)=b(i)+tmp4
+ c(i)=c(i)+tmp2
+ ENDDO
+END SUBROUTINE
+! { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } }
diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc
index 291f2db..72792ce 100644
--- a/gcc/tree-ssa-loop-ch.cc
+++ b/gcc/tree-ssa-loop-ch.cc
@@ -422,6 +422,7 @@ ch_base::copy_headers (function *fun)
{
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "Loop %d never loops.\n", loop->num);
+ scale_loop_profile (loop, profile_probability::always (), 0);
loops_to_unloop.safe_push (loop);
loops_to_unloop_nunroll.safe_push (0);
continue;
@@ -666,6 +667,7 @@ ch_base::copy_headers (function *fun)
{
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "Loop %d no longer loops.\n", loop->num);
+ scale_loop_profile (loop, profile_probability::always (), 0);
loops_to_unloop.safe_push (loop);
loops_to_unloop_nunroll.safe_push (0);
}
diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc
index 9e119eb..0117dbf 100644
--- a/gcc/tree-ssa-loop-ivcanon.cc
+++ b/gcc/tree-ssa-loop-ivcanon.cc
@@ -906,6 +906,10 @@ try_unroll_loop_completely (class loop *loop,
if (may_be_zero)
bitmap_clear_bit (wont_exit, 1);
+ /* If loop was originally estimated to iterate too many times,
+ reduce the profile to avoid new profile inconsistencies. */
+ scale_loop_profile (loop, profile_probability::always (), n_unroll);
+
if (!gimple_duplicate_loop_body_to_header_edge (
loop, loop_preheader_edge (loop), n_unroll, wont_exit, exit,
&edges_to_remove,
@@ -919,6 +923,8 @@ try_unroll_loop_completely (class loop *loop,
free_original_copy_tables ();
}
+ else
+ scale_loop_profile (loop, profile_probability::always (), 0);
/* Remove the conditional from the last copy of the loop. */
if (edge_to_cancel)