Fix ipa-cp wrt volatile loads
authorJan Hubicka <jh@suse.cz>
Tue, 14 Jun 2022 12:05:53 +0000 (14:05 +0200)
committerJakub Jelinek <jakub@redhat.com>
Sun, 19 Jun 2022 10:08:35 +0000 (12:08 +0200)
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.

(cherry picked from commit 8f6c317b3a16350698f3c9e0accb43a9b4acb4ae)

gcc/ipa-prop.cc
gcc/testsuite/gcc.dg/ipa/pr105739.c [new file with mode: 0644]

index 7c7bba0..55c9c37 100644 (file)
@@ -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 (file)
index 0000000..8dbe8fc
--- /dev/null
@@ -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" } } */