Index: gcc/params.def
===================================================================
--- gcc/params.def	(revision 207155)
+++ gcc/params.def	(working copy)
@@ -339,6 +339,11 @@ DEFPARAM(PARAM_MAX_COMPLETELY_PEELED_INSNS,
 	"max-completely-peeled-insns",
 	"The maximum number of insns of a completely peeled loop",
 	400, 0, 0)
+/* The default maximum number of insns of a peeled loop, with -O2.  */
+DEFPARAM(PARAM_MAX_DEFAULT_COMPLETELY_PEELED_INSNS,
+	"max-default-completely-peeled-insns",
+	"The maximum number of insns of a completely peeled loop",
+	200, 0, 0)
 /* The maximum number of peelings of a single loop that is peeled completely.  */
 DEFPARAM(PARAM_MAX_COMPLETELY_PEEL_TIMES,
 	"max-completely-peel-times",
Index: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 207155)
+++ gcc/opts.c	(working copy)
@@ -855,6 +855,18 @@ finish_options (struct gcc_options *opts, struct g
             0, opts->x_param_values, opts_set->x_param_values);
     }
 
+  /* Set PARAM_MAX_COMPLETELY_PEELED_INSNS to the default original value during
+     -O2 when -funroll-loops and -fpeel-loops are not set.   */
+  if (optimize == 2 && !opts->x_flag_unroll_loops && !opts->x_flag_peel_loops
+      && !opts->x_flag_unroll_all_loops)
+
+    {
+      maybe_set_param_value
+       (PARAM_MAX_COMPLETELY_PEELED_INSNS,
+        PARAM_VALUE (PARAM_MAX_DEFAULT_COMPLETELY_PEELED_INSNS),
+	opts->x_param_values, opts_set->x_param_values);
+    }
+
   /* Set PARAM_MAX_STORES_TO_SINK to 0 if either vectorization or if-conversion
      is disabled.  */
   if ((!opts->x_flag_tree_loop_vectorize && !opts->x_flag_tree_slp_vectorize)
Index: gcc/tree-ssa-loop.c
===================================================================
--- gcc/tree-ssa-loop.c	(revision 207155)
+++ gcc/tree-ssa-loop.c	(working copy)
@@ -467,7 +467,7 @@ tree_complete_unroll (void)
 
   return tree_unroll_loops_completely (flag_unroll_loops
 				       || flag_peel_loops
-				       || optimize >= 3, true);
+				       || optimize >= 2, true);
 }
 
 static bool
Index: gcc/testsuite/gcc.target/i386/bmi2-bzhi64-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi2-bzhi64-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi2-bzhi64-1a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { ! ia32 } } } */
-/* { dg-options "-mbmi2 -O2 -dp" } */
+/* { dg-options "-mbmi2 -O2 -dp --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi2-bzhi64-1.c"
 
Index: gcc/testsuite/gcc.target/i386/bmi2-pext32-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi2-pext32-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi2-pext32-1a.c	(working copy)
@@ -3,4 +3,4 @@
 
 #include "bmi2-pext32-1.c"
 
-/* { dg-final { scan-assembler-times "bmi2_pext_si3" 1 } } */
+/* { dg-final { scan-assembler "bmi2_pext_si3" } } */
Index: gcc/testsuite/gcc.target/i386/avx2-vpaddb-3.c
===================================================================
--- gcc/testsuite/gcc.target/i386/avx2-vpaddb-3.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/avx2-vpaddb-3.c	(working copy)
@@ -8,5 +8,5 @@
 
 #include "avx2-vpop-check.h"
 
-/* { dg-final { scan-assembler-times "vpaddb\[ \\t\]+\[^\n\]*%ymm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler "vpaddb\[ \\t\]+\[^\n\]*%ymm\[0-9\]" } } */
 /* { dg-final { cleanup-saved-temps } } */
Index: gcc/testsuite/gcc.target/i386/bmi-blsr-2a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-blsr-2a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-blsr-2a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mbmi -fno-inline -dp" } */
+/* { dg-options "-O2 -mbmi -fno-inline -dp  --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-blsr-2.c"
 
Index: gcc/testsuite/gcc.target/i386/avx2-vpsubw-3.c
===================================================================
--- gcc/testsuite/gcc.target/i386/avx2-vpsubw-3.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/avx2-vpsubw-3.c	(working copy)
@@ -8,5 +8,5 @@
 
 #include "avx2-vpop-check.h"
 
-/* { dg-final { scan-assembler-times "vpsubw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler "vpsubw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" } } */
 /* { dg-final { cleanup-saved-temps } } */
Index: gcc/testsuite/gcc.target/i386/avx2-vpsrlw-3.c
===================================================================
--- gcc/testsuite/gcc.target/i386/avx2-vpsrlw-3.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/avx2-vpsrlw-3.c	(working copy)
@@ -8,5 +8,5 @@
 
 #include "avx2-vpop-check.h"
 
-/* { dg-final { scan-assembler-times "vpsrlw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler "vpsrlw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" } } */
 /* { dg-final { cleanup-saved-temps } } */
Index: gcc/testsuite/gcc.target/i386/bmi-tzcnt-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-tzcnt-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-tzcnt-1a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { ! ia32 } } } */
-/* { dg-options "-O2 -mbmi -fno-inline" } */
+/* { dg-options "-O2 -mbmi -fno-inline --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-tzcnt-1.c"
 
Index: gcc/testsuite/gcc.target/i386/avx2-vpaddw-3.c
===================================================================
--- gcc/testsuite/gcc.target/i386/avx2-vpaddw-3.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/avx2-vpaddw-3.c	(working copy)
@@ -8,5 +8,5 @@
 
 #include "avx2-vpop-check.h"
 
-/* { dg-final { scan-assembler-times "vpaddw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler "vpaddw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" } } */
 /* { dg-final { cleanup-saved-temps } } */
Index: gcc/testsuite/gcc.target/i386/avx2-vpsraw-3.c
===================================================================
--- gcc/testsuite/gcc.target/i386/avx2-vpsraw-3.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/avx2-vpsraw-3.c	(working copy)
@@ -8,5 +8,5 @@
 
 #include "avx2-vpop-check.h"
 
-/* { dg-final { scan-assembler-times "vpsraw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler "vpsraw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" } } */
 /* { dg-final { cleanup-saved-temps } } */
Index: gcc/testsuite/gcc.target/i386/bmi-blsi-2a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-blsi-2a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-blsi-2a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mbmi -fno-inline -dp" } */
+/* { dg-options "-O2 -mbmi -fno-inline -dp --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-blsi-2.c"
 
Index: gcc/testsuite/gcc.target/i386/bmi-blsr-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-blsr-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-blsr-1a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { ! ia32 } } } */
-/* { dg-options "-O2 -mbmi -fno-inline -dp" } */
+/* { dg-options "-O2 -mbmi -fno-inline -dp  --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-blsr-1.c"
 
Index: gcc/testsuite/gcc.target/i386/bmi-bextr-2a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-bextr-2a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-bextr-2a.c	(working copy)
@@ -3,4 +3,4 @@
 
 #include "bmi-bextr-2.c"
 
-/* { dg-final { scan-assembler-times "bmi_bextr_si" 1 } } */
+/* { dg-final { scan-assembler "bmi_bextr_si" } } */
Index: gcc/testsuite/gcc.target/i386/bmi-blsi-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-blsi-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-blsi-1a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { ! ia32 } } } */
-/* { dg-options "-O2 -mbmi -fno-inline -dp" } */
+/* { dg-options "-O2 -mbmi -fno-inline -dp --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-blsi-1.c"
 
Index: gcc/testsuite/gcc.target/i386/bmi2-pext64-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi2-pext64-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi2-pext64-1a.c	(working copy)
@@ -3,4 +3,4 @@
 
 #include "bmi2-pext64-1.c"
 
-/* { dg-final { scan-assembler-times "bmi2_pext_di3" 1 } } */
+/* { dg-final { scan-assembler "bmi2_pext_di3" } } */
Index: gcc/testsuite/gcc.target/i386/avx2-vpmullw-3.c
===================================================================
--- gcc/testsuite/gcc.target/i386/avx2-vpmullw-3.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/avx2-vpmullw-3.c	(working copy)
@@ -8,5 +8,5 @@
 
 #include "avx2-vpop-check.h"
 
-/* { dg-final { scan-assembler-times "vpmullw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler "vpmullw\[ \\t\]+\[^\n\]*%ymm\[0-9\]" } } */
 /* { dg-final { cleanup-saved-temps } } */
Index: gcc/testsuite/gcc.target/i386/bmi2-pdep32-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi2-pdep32-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi2-pdep32-1a.c	(working copy)
@@ -3,4 +3,4 @@
 
 #include "bmi2-pdep32-1.c"
 
-/* { dg-final { scan-assembler-times "bmi2_pdep_si3" 1 } } */
+/* { dg-final { scan-assembler "bmi2_pdep_si3" } } */
Index: gcc/testsuite/gcc.target/i386/bmi-andn-2a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-andn-2a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-andn-2a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mbmi -fno-inline -dp" } */
+/* { dg-options "-O2 -mbmi -fno-inline -dp  --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-andn-2.c"
 
Index: gcc/testsuite/gcc.target/i386/bmi2-bzhi32-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi2-bzhi32-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi2-bzhi32-1a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-mbmi2 -O2 -dp" } */
+/* { dg-options "-mbmi2 -O2 -dp --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi2-bzhi32-1.c"
 
Index: gcc/testsuite/gcc.target/i386/bmi-blsmsk-2a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-blsmsk-2a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-blsmsk-2a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mbmi -fno-inline -dp" } */
+/* { dg-options "-O2 -mbmi -fno-inline -dp  --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-blsmsk-2.c"
 
Index: gcc/testsuite/gcc.target/i386/recip-vec-sqrtf-avx.c
===================================================================
--- gcc/testsuite/gcc.target/i386/recip-vec-sqrtf-avx.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/recip-vec-sqrtf-avx.c	(working copy)
@@ -31,4 +31,4 @@ void t3(void)
    r[i] = sqrtf (a[i]);
 }
 
-/* { dg-final { scan-assembler-times "vrsqrtps\[ \\t\]+\[^\n\]*%ymm" 3 } } */
+/* { dg-final { scan-assembler "vrsqrtps\[ \\t\]+\[^\n\]*%ymm" } } */
Index: gcc/testsuite/gcc.target/i386/bmi-bextr-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-bextr-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-bextr-1a.c	(working copy)
@@ -3,4 +3,4 @@
 
 #include "bmi-bextr-1.c"
 
-/* { dg-final { scan-assembler-times "bmi_bextr_di" 1 } } */
+/* { dg-final { scan-assembler "bmi_bextr_di" } } */
Index: gcc/testsuite/gcc.target/i386/bmi-andn-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-andn-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-andn-1a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { ! ia32 } } } */
-/* { dg-options "-O2 -mbmi -fno-inline -dp" } */
+/* { dg-options "-O2 -mbmi -fno-inline -dp --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-andn-1.c"
 
Index: gcc/testsuite/gcc.target/i386/bmi-blsmsk-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-blsmsk-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-blsmsk-1a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { ! ia32 } } } */
-/* { dg-options "-O2 -mbmi -fno-inline -dp" } */
+/* { dg-options "-O2 -mbmi -fno-inline -dp  --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-blsmsk-1.c"
 
Index: gcc/testsuite/gcc.target/i386/bmi-tzcnt-2a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi-tzcnt-2a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi-tzcnt-2a.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mbmi -fno-inline" } */
+/* { dg-options "-O2 -mbmi -fno-inline --param max-default-completely-peeled-insns=0" } */
 
 #include "bmi-tzcnt-2.c"
 
Index: gcc/testsuite/gcc.target/i386/avx2-vpsubb-3.c
===================================================================
--- gcc/testsuite/gcc.target/i386/avx2-vpsubb-3.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/avx2-vpsubb-3.c	(working copy)
@@ -8,5 +8,5 @@
 
 #include "avx2-vpop-check.h"
 
-/* { dg-final { scan-assembler-times "vpsubb\[ \\t\]+\[^\n\]*%ymm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler "vpsubb\[ \\t\]+\[^\n\]*%ymm\[0-9\]" } } */
 /* { dg-final { cleanup-saved-temps } } */
Index: gcc/testsuite/gcc.target/i386/bmi2-pdep64-1a.c
===================================================================
--- gcc/testsuite/gcc.target/i386/bmi2-pdep64-1a.c	(revision 207155)
+++ gcc/testsuite/gcc.target/i386/bmi2-pdep64-1a.c	(working copy)
@@ -3,4 +3,4 @@
 
 #include "bmi2-pdep64-1.c"
 
-/* { dg-final { scan-assembler-times "bmi2_pdep_di3" 1 } } */
+/* { dg-final { scan-assembler "bmi2_pdep_di3" } } */
Index: gcc/testsuite/gcc.dg/pr53265.c
===================================================================
--- gcc/testsuite/gcc.dg/pr53265.c	(revision 207155)
+++ gcc/testsuite/gcc.dg/pr53265.c	(working copy)
@@ -154,3 +154,5 @@ fn12 (void)
   fn11 (1);
   fn11 (1);
 }
+
+/* { dg-prune-output "array subscript is above array bounds" } */
