public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1089] Fix ipa-cp wrt volatile loads
@ 2022-06-14 12:07 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2022-06-14 12:07 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8f6c317b3a16350698f3c9e0accb43a9b4acb4ae

commit r13-1089-g8f6c317b3a16350698f3c9e0accb43a9b4acb4ae
Author: Jan Hubicka <jh@suse.cz>
Date:   Tue Jun 14 14:05:53 2022 +0200

    Fix ipa-cp wrt volatile loads
    
    Check for volatile flag to ipa_load_from_parm_agg.
    
    gcc/ChangeLog:
    
    2022-06-10  Jan Hubicka  <hubicka@ucw.cz>
    
            PR ipa/105739
            * ipa-prop.cc (ipa_load_from_parm_agg): Punt on volatile loads.
    
    gcc/testsuite/ChangeLog:
    
    2022-06-10  Jan Hubicka  <hubicka@ucw.cz>
    
            * gcc.dg/ipa/pr105739.c: New test.

Diff:
---
 gcc/ipa-prop.cc                     |  4 ++++
 gcc/testsuite/gcc.dg/ipa/pr105739.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

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] only message in thread

only message in thread, other threads:[~2022-06-14 12:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-14 12:07 [gcc r13-1089] Fix ipa-cp wrt volatile loads Jan Hubicka

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).