The following expands the RMW bit clear/set pattern detection to
also cover VIEW_CONVERT_EXPR as it appears when generic word_mode
vectorization is involved.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/110743
* tree-ssa-uninit.cc (maybe_warn_operand): Also cover
VIEW_CONVERT_EXPR uses for RMW bit clear/set pattern
detection.
* gcc.dg/uninit-pr110743-2.c: New testcase.
---
gcc/testsuite/gcc.dg/uninit-pr110743-2.c | 19 +++++++++++++++++++
gcc/tree-ssa-uninit.cc | 7 +++++--
2 files changed, 24 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/uninit-pr110743-2.c
diff --git a/gcc/testsuite/gcc.dg/uninit-pr110743-2.c
b/gcc/testsuite/gcc.dg/uninit-pr110743-2.c
new file mode 100644
index 00000000000..8119bb49bbf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-pr110743-2.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftrivial-auto-var-init=pattern -Wuninitialized" } */
+/* { dg-additional-options "-mgeneral-regs-only" { target { aarch64-*-*
x86_64-*-* i?86-*-* } } } */
+
+struct layer_mask {
+ unsigned int x : 17;
+ unsigned int y : 1;
+} __attribute__((__packed__)) __attribute__((__aligned__(sizeof (unsigned
int))));
+struct layer_masks {
+ struct layer_mask layers[16];
+};
+
+void bar (struct layer_masks *);
+
+void foo ()
+{
+ struct layer_masks layer_masks; /* { dg-bogus "uninitialized" } */
+ bar (&layer_masks);
+}
diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc
index 107ed21e10b..1072e1e270b 100644
--- a/gcc/tree-ssa-uninit.cc
+++ b/gcc/tree-ssa-uninit.cc
@@ -768,13 +768,16 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs,
tree rhs,
&& single_imm_use (lhs, &luse_p, &use_stmt))
{
gassign *use_ass = dyn_cast <gassign *> (use_stmt);
- for (int i = 0; i < 2; ++i)
+ for (int i = 0; i < 4; ++i)
if (use_ass
&& (gimple_assign_rhs_code (use_ass) == BIT_AND_EXPR
- || gimple_assign_rhs_code (use_ass) == BIT_IOR_EXPR)
+ || gimple_assign_rhs_code (use_ass) == BIT_IOR_EXPR
+ || gimple_assign_rhs_code (use_ass) == VIEW_CONVERT_EXPR)
&& single_imm_use (gimple_assign_lhs (use_ass), &luse_p,
&use_stmt))
use_ass = dyn_cast <gassign *> (use_stmt);
+ else
+ break;
if (use_ass
&& gimple_vdef (use_ass)
&& operand_equal_p (gimple_assign_rhs1 (stmt),
--
2.51.0