Fix PR tree-optimization/108199
Checks
Commit Message
Hi,
this fixes the problematic interaction between bitfields, unions, SSO and SRA.
Tested on x86-64/Linux and SPARC/Solaris, OK for all active branches?
2023-01-11 Eric Botcazou <ebotcazou@adacore.com>
Andreas Krebbel <krebbel@linux.ibm.com>
PR tree-optimization/108199
* tree-sra.cc (sra_modify_expr): Deal with reverse storage order
for bit-field references.
2023-01-11 Eric Botcazou <ebotcazou@adacore.com>
* gcc.dg/sso-17.c: New test.
Comments
On Wed, Jan 11, 2023 at 11:00 AM Eric Botcazou via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi,
>
> this fixes the problematic interaction between bitfields, unions, SSO and SRA.
>
> Tested on x86-64/Linux and SPARC/Solaris, OK for all active branches?
OK.
Thanks,
Richard.
>
> 2023-01-11 Eric Botcazou <ebotcazou@adacore.com>
> Andreas Krebbel <krebbel@linux.ibm.com>
>
> PR tree-optimization/108199
> * tree-sra.cc (sra_modify_expr): Deal with reverse storage order
> for bit-field references.
>
>
> 2023-01-11 Eric Botcazou <ebotcazou@adacore.com>
>
> * gcc.dg/sso-17.c: New test.
>
> --
> Eric Botcazou
@@ -3858,7 +3858,23 @@ sra_modify_expr (tree *expr, gimple_stmt_iterator *gsi, bool write)
}
}
else
- *expr = repl;
+ {
+ /* If we are going to replace a scalar field in a structure with
+ reverse storage order by a stand-alone scalar, we are going to
+ effectively byte-swap the scalar and we also need to byte-swap
+ the portion of it represented by the bit-field. */
+ if (bfr && REF_REVERSE_STORAGE_ORDER (bfr))
+ {
+ REF_REVERSE_STORAGE_ORDER (bfr) = 0;
+ TREE_OPERAND (bfr, 2)
+ = size_binop (MINUS_EXPR, TYPE_SIZE (TREE_TYPE (repl)),
+ size_binop (PLUS_EXPR, TREE_OPERAND (bfr, 1),
+ TREE_OPERAND (bfr, 2)));
+ }
+
+ *expr = repl;
+ }
+
sra_stats.exprs++;
}
else if (write && access->grp_to_be_debug_replaced)