aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2020-05-06 09:39:45 +0200
committerRichard Biener <rguenther@suse.de>2020-05-06 12:39:24 +0200
commit371905d12259c180efb9b1f1b5716e969feb60f9 (patch)
tree5cfdd80887d702d6de60cbeab7cf467c5a2eddf3 /gcc
parent6208287fcaf01d3f300442c14a2c13815fbb3191 (diff)
downloadgcc-371905d12259c180efb9b1f1b5716e969feb60f9.zip
gcc-371905d12259c180efb9b1f1b5716e969feb60f9.tar.gz
gcc-371905d12259c180efb9b1f1b5716e969feb60f9.tar.bz2
tree-optimization/94963 - avoid bogus uninit warning with store-motion
Eliding the load for store-motion causes an uninitialized variable flowing into the loop, conditionally initialized and used. The uninit warning cannot relate the flag used to guard the initialization and use with the actual initialization so the following robustifies the previous approach of marking the conditional store as not to be warned on by instead initializing the variable on loop entry from an uninitialized variable we mark as not to be warned for. 2020-05-06 Richard Biener <rguenther@suse.de> PR tree-optimization/94963 * tree-ssa-loop-im.c (execute_sm_if_changed): Remove no-warning marking of the conditional store. (execute_sm): Instead mark the uninitialized state on loop entry to be not warned about. * gcc.dg/pr94963.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr94963.c35
-rw-r--r--gcc/tree-ssa-loop-im.c18
4 files changed, 59 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c40d887..73a6015 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2020-05-06 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/94963
+ * tree-ssa-loop-im.c (execute_sm_if_changed): Remove
+ no-warning marking of the conditional store.
+ (execute_sm): Instead mark the uninitialized state
+ on loop entry to be not warned about.
+
2020-05-06 Hongtao Liu <hongtao.liu@intel.com>
* common/config/i386/i386-common.c (OPTION_MASK_ISA2_TSXLDTRK_SET,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b917e81..a3cf68d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-06 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/94963
+ * gcc.dg/pr94963.c: New testcase.
+
2020-05-06 Hongtao Liu <hongtao.liu@intel.com>
* g++.dg/other/i386-2.c: Add -mtsxldtrk.
diff --git a/gcc/testsuite/gcc.dg/pr94963.c b/gcc/testsuite/gcc.dg/pr94963.c
new file mode 100644
index 0000000..aca9e16
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr94963.c
@@ -0,0 +1,35 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+typedef struct
+{
+ int p1;
+ int p2;
+ int p3;
+} P;
+struct S
+{
+ int field;
+};
+extern int v2;
+extern void foo (struct S *map);
+static struct S var;
+const P *pv;
+int ps;
+void
+f (void)
+{
+ if (pv != 0)
+ for (const P *ph = pv; ph < &pv[ps]; ++ph)
+ switch (ph->p1)
+ {
+ case 1:
+ v2 = ph->p2;
+ break;
+ case 2:
+ var.field = ph->p3;
+ break;
+ }
+ if (var.field != 0) /* { dg-bogus "uninitialized" } */
+ foo (&var);
+}
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index 554dd4b..3056b4b 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -1994,8 +1994,6 @@ execute_sm_if_changed (edge ex, tree mem, tree tmp_var, tree flag,
gsi = gsi_start_bb (then_bb);
/* Insert actual store. */
stmt = gimple_build_assign (unshare_expr (mem), tmp_var);
- /* Make sure to not warn about maybe-uninit uses of tmp_var here. */
- gimple_set_no_warning (stmt, true);
gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
edge e1 = single_succ_edge (new_bb);
@@ -2149,13 +2147,19 @@ execute_sm (class loop *loop, vec<edge> exits, im_mem_ref *ref)
store then. */
if ((!always_stored && !multi_threaded_model_p)
|| (ref->loaded && bitmap_bit_p (ref->loaded, loop->num)))
+ load = gimple_build_assign (tmp_var, unshare_expr (ref->mem.ref));
+ else
{
- load = gimple_build_assign (tmp_var, unshare_expr (ref->mem.ref));
- lim_data = init_lim_data (load);
- lim_data->max_loop = loop;
- lim_data->tgt_loop = loop;
- gsi_insert_before (&gsi, load, GSI_SAME_STMT);
+ /* If not emitting a load mark the uninitialized state on the
+ loop entry as not to be warned for. */
+ tree uninit = create_tmp_reg (TREE_TYPE (tmp_var));
+ TREE_NO_WARNING (uninit) = 1;
+ load = gimple_build_assign (tmp_var, uninit);
}
+ lim_data = init_lim_data (load);
+ lim_data->max_loop = loop;
+ lim_data->tgt_loop = loop;
+ gsi_insert_before (&gsi, load, GSI_SAME_STMT);
if (multi_threaded_model_p)
{