summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Hubicka <jh@suse.cz>2022-06-14 14:05:53 +0200
committerJakub Jelinek <jakub@redhat.com>2022-06-19 12:08:35 +0200
commitbf4ba940673b80961c5979078f9d37a7bef2f5ff (patch)
treed9c563f4cd44a8e7befb1efc0cb84ccfc5125ec1
parentc++: Fix up ICE on __builtin_shufflevector constexpr evaluation [PR105871] (diff)
downloadgcc-bf4ba940673b80961c5979078f9d37a7bef2f5ff.tar.gz
gcc-bf4ba940673b80961c5979078f9d37a7bef2f5ff.tar.bz2
gcc-bf4ba940673b80961c5979078f9d37a7bef2f5ff.tar.xz
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. (cherry picked from commit 8f6c317b3a16350698f3c9e0accb43a9b4acb4ae)
-rw-r--r--gcc/ipa-prop.cc4
-rw-r--r--gcc/testsuite/gcc.dg/ipa/pr105739.c30
2 files changed, 34 insertions, 0 deletions
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 7c7bba0c770..55c9c375702 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,
1112 if (!base) 1112 if (!base)
1113 return false; 1113 return false;
1114 1114
1115 /* We can not propagate across volatile loads. */
1116 if (TREE_THIS_VOLATILE (op))
1117 return false;
1118
1115 if (DECL_P (base)) 1119 if (DECL_P (base))
1116 { 1120 {
1117 int index = ipa_get_param_decl_index_1 (descriptors, base); 1121 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 @@
1/* { dg-do compile } */
2/* { dg-options "-O2 -fdump-tree-optimized" } */
3
4
5__attribute__((noinline))
6static int
7test2(int a)
8{
9 if (__builtin_constant_p (a))
10 __builtin_abort ();
11 return a;
12}
13static int
14test(int *a)
15{
16 int val = *(volatile int *)a;
17 if (__builtin_constant_p (val))
18 __builtin_abort ();
19 if (val)
20 return test2(val);
21 return 0;
22}
23int a;
24int
25main()
26{
27 a = 0;
28 return test (&a);
29}
30/* { dg-final { scan-tree-dump "test2" "optimized" } } */