Re: [PATCH] Implement Bit-field lowering

2023-07-19 Thread Richard Biener via Gcc-patches
On Fri, Jul 14, 2023 at 7:49 AM naveenh--- via Gcc-patches
 wrote:
>
> From: Naveen H S 
>
> This patch adds lowering bit-field and opposite endian accesses pass.
> The patch addresses many issues in:-
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19466

A little bit more description would be nice ...

> 2023-07-14  Andrew Pinski   
> Co-authored-by: Naveen H S 
>
> gcc/ChangeLog:

And some bug references for bugzilla.  In fact you don't add any testcases
that are presumably fixed?

> * Makefile.in (OBJS): Add gimple-lower-accesses.o.
> * gimple-lower-accesses.cc: New file.
> * passes.def (pass_lower_accesses): Add.
> * tree-pass.h (make_pass_lower_accesses): Define.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/store_merging_14.c: Modify the pattern found as per new code.
> * gcc.dg/store_merging_16.c: Likewise.
> * gcc.dg/store_merging_20.c: Likewise.
> * gcc.dg/store_merging_21.c: Likewise.
> * gcc.dg/store_merging_24.c: Likewise.
> * gcc.dg/store_merging_25.c: Likewise.
> * gcc.dg/store_merging_6.c: Likewise.
> * gcc.dg/tree-ssa/20030729-1.c: Likewise.
> * gcc.dg/tree-ssa/20030814-6.c: Likewise.
> * gcc.dg/tree-ssa/loop-interchange-14.c: Likewise.
> * gcc.dg/tree-ssa/20030714-1.c: Remove.
> ---
>  gcc/Makefile.in   |   1 +
>  gcc/gimple-lower-accesses.cc  | 463 ++
>  gcc/passes.def|   4 +
>  gcc/testsuite/gcc.dg/store_merging_10.c   |   2 +-
>  gcc/testsuite/gcc.dg/store_merging_14.c   |   2 +-
>  gcc/testsuite/gcc.dg/store_merging_16.c   |   4 +-
>  gcc/testsuite/gcc.dg/store_merging_20.c   |   2 +-
>  gcc/testsuite/gcc.dg/store_merging_21.c   |   2 +-
>  gcc/testsuite/gcc.dg/store_merging_24.c   |   4 +-
>  gcc/testsuite/gcc.dg/store_merging_25.c   |   4 +-
>  gcc/testsuite/gcc.dg/store_merging_6.c|   2 +-
>  gcc/testsuite/gcc.dg/tree-ssa/20030714-1.c|  45 --
>  gcc/testsuite/gcc.dg/tree-ssa/20030729-1.c|   5 +-
>  gcc/testsuite/gcc.dg/tree-ssa/20030814-6.c|   5 +-
>  .../gcc.dg/tree-ssa/loop-interchange-14.c |   2 +-
>  gcc/tree-pass.h   |   1 +
>  16 files changed, 485 insertions(+), 63 deletions(-)
>  create mode 100644 gcc/gimple-lower-accesses.cc
>  delete mode 100644 gcc/testsuite/gcc.dg/tree-ssa/20030714-1.c
>
> diff --git a/gcc/Makefile.in b/gcc/Makefile.in
> index c478ec85201..50bd28f4d04 100644
> --- a/gcc/Makefile.in
> +++ b/gcc/Makefile.in
> @@ -1338,6 +1338,7 @@ OBJS = \
> $(GIMPLE_MATCH_PD_SEQ_O) \
> gimple-match-exports.o \
> $(GENERIC_MATCH_PD_SEQ_O) \
> +   gimple-lower-accesses.o \
> insn-attrtab.o \
> insn-automata.o \
> insn-dfatab.o \
> diff --git a/gcc/gimple-lower-accesses.cc b/gcc/gimple-lower-accesses.cc
> new file mode 100644
> index 000..9d87acfba56
> --- /dev/null
> +++ b/gcc/gimple-lower-accesses.cc
> @@ -0,0 +1,463 @@
> +/* GIMPLE lowering bit-field and opposite endian accesses pass.
> +
> +   Copyright (C) 2017-2023 Free Software Foundation, Inc.
> +
> +This file is part of GCC.
> +
> +GCC is free software; you can redistribute it and/or modify it under
> +the terms of the GNU General Public License as published by the Free
> +Software Foundation; either version 3, or (at your option) any later
> +version.
> +
> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> +for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +.  */
> +
> +#include "config.h"
> +#include "system.h"
> +#include "coretypes.h"
> +#include "backend.h"
> +#include "rtl.h"
> +#include "tree.h"
> +#include "gimple.h"
> +#include "cfghooks.h"
> +#include "tree-pass.h"
> +#include "ssa.h"
> +#include "fold-const.h"
> +#include "stor-layout.h"
> +#include "tree-eh.h"
> +#include "gimplify.h"
> +#include "gimple-iterator.h"
> +#include "gimplify-me.h"
> +#include "tree-cfg.h"
> +#include "tree-dfa.h"
> +#include "tree-ssa.h"
> +#include "tree-ssa-propagate.h"
> +#include "tree-hasher.h"
> +#include "cfgloop.h"
> +#include "cfganal.h"
> +#include "alias.h"
> +#include "expr.h"
> +#include "tree-pretty-print.h"
> +
> +namespace {
> +
> +class lower_accesses
> +{
> +  function *fn;
> +public:
> +  lower_accesses (function *f) : fn(f) {}
> +  unsigned int execute (void);
> +};

please merge this with the gimple_opt_pass class

> +
> +
> +/* Handle reference to a bitfield EXPR.
> +   If BITPOS_P is non-null assume that reference is LHS and set *BITPOS_P
> +   to bit position of the field.
> +   If REF_P is non-null set it to the memory reference for the encompassing
> +   allocation unit.

there is no REF_P argument.

BITSIZE_P and PREVESEP are undocumented.

> +   Note 

[PATCH] Implement Bit-field lowering

2023-07-13 Thread naveenh--- via Gcc-patches
From: Naveen H S 

This patch adds lowering bit-field and opposite endian accesses pass.
The patch addresses many issues in:-
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19466

2023-07-14  Andrew Pinski   
Co-authored-by: Naveen H S 

gcc/ChangeLog:

* Makefile.in (OBJS): Add gimple-lower-accesses.o.
* gimple-lower-accesses.cc: New file.
* passes.def (pass_lower_accesses): Add.
* tree-pass.h (make_pass_lower_accesses): Define.

gcc/testsuite/ChangeLog:

* gcc.dg/store_merging_14.c: Modify the pattern found as per new code.
* gcc.dg/store_merging_16.c: Likewise.
* gcc.dg/store_merging_20.c: Likewise.
* gcc.dg/store_merging_21.c: Likewise.
* gcc.dg/store_merging_24.c: Likewise.
* gcc.dg/store_merging_25.c: Likewise.
* gcc.dg/store_merging_6.c: Likewise.
* gcc.dg/tree-ssa/20030729-1.c: Likewise.
* gcc.dg/tree-ssa/20030814-6.c: Likewise.
* gcc.dg/tree-ssa/loop-interchange-14.c: Likewise.
* gcc.dg/tree-ssa/20030714-1.c: Remove.
---
 gcc/Makefile.in   |   1 +
 gcc/gimple-lower-accesses.cc  | 463 ++
 gcc/passes.def|   4 +
 gcc/testsuite/gcc.dg/store_merging_10.c   |   2 +-
 gcc/testsuite/gcc.dg/store_merging_14.c   |   2 +-
 gcc/testsuite/gcc.dg/store_merging_16.c   |   4 +-
 gcc/testsuite/gcc.dg/store_merging_20.c   |   2 +-
 gcc/testsuite/gcc.dg/store_merging_21.c   |   2 +-
 gcc/testsuite/gcc.dg/store_merging_24.c   |   4 +-
 gcc/testsuite/gcc.dg/store_merging_25.c   |   4 +-
 gcc/testsuite/gcc.dg/store_merging_6.c|   2 +-
 gcc/testsuite/gcc.dg/tree-ssa/20030714-1.c|  45 --
 gcc/testsuite/gcc.dg/tree-ssa/20030729-1.c|   5 +-
 gcc/testsuite/gcc.dg/tree-ssa/20030814-6.c|   5 +-
 .../gcc.dg/tree-ssa/loop-interchange-14.c |   2 +-
 gcc/tree-pass.h   |   1 +
 16 files changed, 485 insertions(+), 63 deletions(-)
 create mode 100644 gcc/gimple-lower-accesses.cc
 delete mode 100644 gcc/testsuite/gcc.dg/tree-ssa/20030714-1.c

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index c478ec85201..50bd28f4d04 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1338,6 +1338,7 @@ OBJS = \
$(GIMPLE_MATCH_PD_SEQ_O) \
gimple-match-exports.o \
$(GENERIC_MATCH_PD_SEQ_O) \
+   gimple-lower-accesses.o \
insn-attrtab.o \
insn-automata.o \
insn-dfatab.o \
diff --git a/gcc/gimple-lower-accesses.cc b/gcc/gimple-lower-accesses.cc
new file mode 100644
index 000..9d87acfba56
--- /dev/null
+++ b/gcc/gimple-lower-accesses.cc
@@ -0,0 +1,463 @@
+/* GIMPLE lowering bit-field and opposite endian accesses pass.
+
+   Copyright (C) 2017-2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "rtl.h"
+#include "tree.h"
+#include "gimple.h"
+#include "cfghooks.h"
+#include "tree-pass.h"
+#include "ssa.h"
+#include "fold-const.h"
+#include "stor-layout.h"
+#include "tree-eh.h"
+#include "gimplify.h"
+#include "gimple-iterator.h"
+#include "gimplify-me.h"
+#include "tree-cfg.h"
+#include "tree-dfa.h"
+#include "tree-ssa.h"
+#include "tree-ssa-propagate.h"
+#include "tree-hasher.h"
+#include "cfgloop.h"
+#include "cfganal.h"
+#include "alias.h"
+#include "expr.h"
+#include "tree-pretty-print.h"
+
+namespace {
+
+class lower_accesses
+{
+  function *fn;
+public:
+  lower_accesses (function *f) : fn(f) {}
+  unsigned int execute (void);
+};
+
+
+/* Handle reference to a bitfield EXPR.
+   If BITPOS_P is non-null assume that reference is LHS and set *BITPOS_P
+   to bit position of the field.
+   If REF_P is non-null set it to the memory reference for the encompassing
+   allocation unit.
+   Note *BITPOS_P is suitable only for BIT_FIELD_REF/BIT_FIELD_INSERT.  */
+
+tree
+extract_bitfield (tree expr, tree *bitpos_p, tree *bitsize_p,
+ bool *preversep)
+{
+  tree base, addr, ref;
+  tree base_type;
+  tree bytepos;
+  machine_mode mode1;
+  int unsignedp = false, volatilep = false, reversep = false;
+
+  poly_int64 bitsize, bitpos;
+  HOST_WIDE_INT ibitsize = 0, ibitpos = 0;
+
+  poly_uint64 bitregion_start = 0;
+  poly_uint64 bitregion_end = 0;
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+{
+  fprintf (dump_file, "Trying to expand bitfield reference: \n");
+