From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1971) id A237E3858D20; Fri, 20 Oct 2023 16:03:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A237E3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697817814; bh=ZDzt/TQQW/hKdfPU2AyfOkOwF/iav02/mW7zmA3yhVA=; h=From:To:Subject:Date:From; b=Y+aV20Q/nl4vA4Fu/XF+kRAwHE4SbvaQ6PQWn7mIHvwz3HZzRfSEThxH2s7o+IlG0 ugZx1P9bLS/1gH6wQbFA86iZAhlk51rlWid0iaWQNDXSfT4SOF2YdERZXB6ea78S9O PYdp29fwKCgx42B/awSSi4frY9uIq4F/bq7pncb4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andre Simoes Dias Vieira To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4798] ifcvt: Don't lower bitfields with non-constant offsets [PR 111882] X-Act-Checkin: gcc X-Git-Author: Andre Vieira X-Git-Refname: refs/heads/master X-Git-Oldrev: c29d55234e3577021b7dabb623e69732fb1407ce X-Git-Newrev: 24cf1f600b8ad34c68a51f48884e72d01f729893 Message-Id: <20231020160334.A237E3858D20@sourceware.org> Date: Fri, 20 Oct 2023 16:03:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:24cf1f600b8ad34c68a51f48884e72d01f729893 commit r14-4798-g24cf1f600b8ad34c68a51f48884e72d01f729893 Author: Andre Vieira Date: Fri Oct 20 17:02:32 2023 +0100 ifcvt: Don't lower bitfields with non-constant offsets [PR 111882] This patch stops lowering of bitfields by ifcvt when they have non-constant offsets as we are not likely to be able to do anything useful with those during vectorization. That also fixes the issue reported in PR 111882, which was being caused by an offset with a side-effect being lowered, but constants have no side-effects so we will no longer run into that problem. gcc/ChangeLog: PR tree-optimization/111882 * tree-if-conv.cc (get_bitfield_rep): Return NULL_TREE for bitfields with non-constant offsets. gcc/testsuite/ChangeLog: * gcc.dg/vect/pr111882.c: New test. Diff: --- gcc/testsuite/gcc.dg/vect/pr111882.c | 15 +++++++++++++++ gcc/tree-if-conv.cc | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/vect/pr111882.c b/gcc/testsuite/gcc.dg/vect/pr111882.c new file mode 100644 index 000000000000..024ad57b6930 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr111882.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-additional-options { -fdump-tree-ifcvt-all } } */ + +static void __attribute__((noipa)) f(int n) { + int i, j; + struct S { char d[n]; int a; int b : 17; int c : 12; }; + struct S A[100][1111]; + for (i = 0; i < 100; i++) { + asm volatile("" : : "g"(&A[0][0]) : "memory"); + for (j = 0; j < 1111; j++) A[i][j].b = 2; + } +} +void g(void) { f(1); } + +/* { dg-final { scan-tree-dump-not "Bitfield OK to lower" "ifcvt" } } */ diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index dab7eeb7707a..262765139ff3 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -3495,6 +3495,7 @@ get_bitfield_rep (gassign *stmt, bool write, tree *bitpos, : gimple_assign_rhs1 (stmt); tree field_decl = TREE_OPERAND (comp_ref, 1); + tree ref_offset = component_ref_field_offset (comp_ref); tree rep_decl = DECL_BIT_FIELD_REPRESENTATIVE (field_decl); /* Bail out if the representative is not a suitable type for a scalar @@ -3509,6 +3510,15 @@ get_bitfield_rep (gassign *stmt, bool write, tree *bitpos, if (compare_tree_int (DECL_SIZE (field_decl), bf_prec) != 0) return NULL_TREE; + if (TREE_CODE (DECL_FIELD_OFFSET (rep_decl)) != INTEGER_CST + || TREE_CODE (ref_offset) != INTEGER_CST) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "\t Bitfield NOT OK to lower," + " offset is non-constant.\n"); + return NULL_TREE; + } + if (struct_expr) *struct_expr = TREE_OPERAND (comp_ref, 0); @@ -3529,7 +3539,7 @@ get_bitfield_rep (gassign *stmt, bool write, tree *bitpos, the structure and the container from the number of bits from the start of the structure and the actual bitfield member. */ tree bf_pos = fold_build2 (MULT_EXPR, bitsizetype, - DECL_FIELD_OFFSET (field_decl), + ref_offset, build_int_cst (bitsizetype, BITS_PER_UNIT)); bf_pos = fold_build2 (PLUS_EXPR, bitsizetype, bf_pos, DECL_FIELD_BIT_OFFSET (field_decl));