rs6000: Fix up flag_shrink_wrap handling in presence of -mrop-protect [PR101324]

Peter Bergner bergner@linux.ibm.com
Thu Oct 28 03:17:39 GMT 2021


Sorry for reposting, but I forgot to CC the gcc-patches mailing list. :-(


PR101324 shows a problem in disabling shrink-wrapping when using -mrop-protect
when there is a attribute optimize/pragma.  Martin's patch below moves handling
of flag_shrink_wrap so it gets re-disbled when we change or add options.

This passed bootstrap and regtesting with no regressions.  Segher, you
approved Martin's patch in the bugzilla.  Is the test case ok too?

I'll note the test case uses the "new" rop_ok effective-target function which
I submitted as a separate patch.

Peter


2021-10-27  Martin Liska  <mliska@suse.cz>

gcc/
	PR target/101324
	* config/rs6000/rs6000.c (rs6000_option_override_internal): Move the
	disabling of shrink-wrapping when using -mrop-protect from here...
	(rs6000_override_options_after_change): ...to here.

2021-10-27  Peter Bergner  <bergner@linux.ibm.com>

gcc/testsuite/
	PR target/101324
	* gcc.target/powerpc/pr101324.c: New test.


diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index bac959f4ef4..95e0d2cffdd 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -3484,6 +3484,10 @@ rs6000_override_options_after_change (void)
     }
   else if (!OPTION_SET_P (flag_cunroll_grow_size))
     flag_cunroll_grow_size = flag_peel_loops || optimize >= 3;
+
+  /* If we are inserting ROP-protect instructions, disable shrink wrap.  */
+  if (rs6000_rop_protect)
+    flag_shrink_wrap = 0;
 }
 
 #ifdef TARGET_USES_LINUX64_OPT
@@ -4048,10 +4052,6 @@ rs6000_option_override_internal (bool global_init_p)
       && ((rs6000_isa_flags_explicit & OPTION_MASK_QUAD_MEMORY_ATOMIC) == 0))
     rs6000_isa_flags |= OPTION_MASK_QUAD_MEMORY_ATOMIC;
 
-  /* If we are inserting ROP-protect instructions, disable shrink wrap.  */
-  if (rs6000_rop_protect)
-    flag_shrink_wrap = 0;
-
   /* If we can shrink-wrap the TOC register save separately, then use
      -msave-toc-indirect unless explicitly disabled.  */
   if ((rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT) == 0
diff --git a/gcc/testsuite/gcc.target/powerpc/pr101324.c b/gcc/testsuite/gcc.target/powerpc/pr101324.c
new file mode 100644
index 00000000000..d27cc2876f3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr101324.c
@@ -0,0 +1,17 @@
+/* { dg-require-effective-target rop_ok } */
+/* { dg-options "-O1 -mrop-protect -mdejagnu-cpu=power10" } */
+
+extern void foo (void);
+
+long int
+__attribute__ ((__optimize__ ("no-inline")))
+func (long int cond)
+{
+  if (cond)
+    foo ();
+  return cond;
+}
+
+/* Ensure hashst comes after mflr and hashchk comes after ld 0,16(1).  */
+/* { dg-final { scan-assembler "mflr 0.*hashst 0," } } */
+/* { dg-final { scan-assembler "ld 0,16\\\(1\\\).*hashchk 0," } } */


More information about the Gcc-patches mailing list