public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix ipa-prop wrt volatile memory accesses
@ 2022-06-10 13:06 Jan Hubicka
  2022-06-12 18:11 ` Martin Jambor
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Hubicka @ 2022-06-10 13:06 UTC (permalink / raw)
  To: gcc-patches, mjambor

Hi,
this patch prevents ipa-prop from propagating aggregates when load is
volatile.  Martin, does this look OK?  It seem to me that ipa-prop may
need some additional volatile flag checks.

Bootstrapped/regtested x86_64-linux, OK?

Honza

gcc/ChangeLog:

2022-06-10  Jan Hubicka  <hubicka@ucw.cz>

	PR ipa/105739
	* ipa-prop.cc (ipa_load_from_parm_agg): Disqualify volatile memory
	accesses.

gcc/testsuite/ChangeLog:

2022-06-10  Jan Hubicka  <hubicka@ucw.cz>

	* gcc.dg/ipa/pr105739.c: New test.

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index afd9222b5a2..c037668e7d8 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -1112,6 +1112,10 @@ ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
   if (!base)
     return false;
 
+  /* We can not propagate across volatile loads.  */
+  if (TREE_THIS_VOLATILE (op))
+    return false;
+
   if (DECL_P (base))
     {
       int index = ipa_get_param_decl_index_1 (descriptors, base);
diff --git a/gcc/testsuite/gcc.dg/ipa/pr105739.c b/gcc/testsuite/gcc.dg/ipa/pr105739.c
new file mode 100644
index 00000000000..8dbe8fc2494
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr105739.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+
+__attribute__((noinline))
+static int
+test2(int a)
+{
+        if (__builtin_constant_p (a))
+                __builtin_abort ();
+        return a;
+}
+static int
+test(int *a)
+{
+        int val = *(volatile int *)a;
+        if (__builtin_constant_p (val))
+                __builtin_abort ();
+        if (val)
+          return test2(val);
+        return 0;
+}
+int a;
+int
+main()
+{
+        a = 0;
+        return test (&a);
+}
+/* { dg-final { scan-tree-dump "test2" "optimized" } } */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Fix ipa-prop wrt volatile memory accesses
  2022-06-10 13:06 Fix ipa-prop wrt volatile memory accesses Jan Hubicka
@ 2022-06-12 18:11 ` Martin Jambor
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Jambor @ 2022-06-12 18:11 UTC (permalink / raw)
  To: Jan Hubicka, gcc-patches

Hi,

On Fri, Jun 10 2022, Jan Hubicka wrote:
> Hi,
> this patch prevents ipa-prop from propagating aggregates when load is
> volatile.  Martin, does this look OK?  It seem to me that ipa-prop may
> need some additional volatile flag checks.

load_from_unmodified_param_or_agg checks for it, although at a bit weird
place (quite late and it looks like volatile reads from an aggregate
parameter passed by value might still be considered OK).  Building of
IPA_JF_LOAD_AGG jump functions also checks for it.
compute_complex_assign_jump_func and get_ancestor_addr_info look at
mem_refs in addr_exprs, so that should be safe.

From a quick scan of ipa-prop, it seems that only ipa_load_from_parm_agg
missed it (modulo the parenthesis above).

>
> Bootstrapped/regtested x86_64-linux, OK?

Sure, OK, thanks!

Martin


> gcc/ChangeLog:
>
> 2022-06-10  Jan Hubicka  <hubicka@ucw.cz>
>
> 	PR ipa/105739
> 	* ipa-prop.cc (ipa_load_from_parm_agg): Disqualify volatile memory
> 	accesses.
>
> gcc/testsuite/ChangeLog:
>
> 2022-06-10  Jan Hubicka  <hubicka@ucw.cz>
>
> 	* gcc.dg/ipa/pr105739.c: New test.
>
> diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
> index afd9222b5a2..c037668e7d8 100644
> --- a/gcc/ipa-prop.cc
> +++ b/gcc/ipa-prop.cc
> @@ -1112,6 +1112,10 @@ ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
>    if (!base)
>      return false;
>  
> +  /* We can not propagate across volatile loads.  */
> +  if (TREE_THIS_VOLATILE (op))
> +    return false;
> +
>    if (DECL_P (base))
>      {
>        int index = ipa_get_param_decl_index_1 (descriptors, base);
> diff --git a/gcc/testsuite/gcc.dg/ipa/pr105739.c b/gcc/testsuite/gcc.dg/ipa/pr105739.c
> new file mode 100644
> index 00000000000..8dbe8fc2494
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/ipa/pr105739.c
> @@ -0,0 +1,30 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +
> +__attribute__((noinline))
> +static int
> +test2(int a)
> +{
> +        if (__builtin_constant_p (a))
> +                __builtin_abort ();
> +        return a;
> +}
> +static int
> +test(int *a)
> +{
> +        int val = *(volatile int *)a;
> +        if (__builtin_constant_p (val))
> +                __builtin_abort ();
> +        if (val)
> +          return test2(val);
> +        return 0;
> +}
> +int a;
> +int
> +main()
> +{
> +        a = 0;
> +        return test (&a);
> +}
> +/* { dg-final { scan-tree-dump "test2" "optimized" } } */

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-12 18:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10 13:06 Fix ipa-prop wrt volatile memory accesses Jan Hubicka
2022-06-12 18:11 ` Martin Jambor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).