From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 216013858D38; Thu, 27 Apr 2023 11:18:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 216013858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682594329; bh=KPrJclsMTRkTHPuzgndhNqrzIvpP0axs4r7rbBhuLl8=; h=From:To:Subject:Date:From; b=FwdA5BGcSWbx2OI8HWRw2u0gLPNxMkCvlStZN6T937lcCyZnbYbqkASInFlXdpuME ExctFaJywXdzUMHPul/bj8YnlDdwqCX1VvYSbbxaCr79/edBLrNNXdXq0UwNyqV1gt aEWMsE6ZBvoRgSQQqajIgEXuHW2NGKDB98c5ezO4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-296] Properly gimplify handled component chains on registers X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: d89e23f27215fcd822994fb2fad17fcd31eef5e1 X-Git-Newrev: 0403d2957929fa12bbd379e3839a8d0c2160576f Message-Id: <20230427111849.216013858D38@sourceware.org> Date: Thu, 27 Apr 2023 11:18:49 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0403d2957929fa12bbd379e3839a8d0c2160576f commit r14-296-g0403d2957929fa12bbd379e3839a8d0c2160576f Author: Richard Biener Date: Thu Apr 27 11:20:49 2023 +0200 Properly gimplify handled component chains on registers When for example complex lowering wants to extract the imaginary part of a complex variable for lowering a complex move we can end up with it generating __imag > which is valid GENERIC. It then feeds that to the gimplifier via force_gimple_operand but that fails to split up this chain of handled components, generating invalid GIMPLE catched by verification when PR109644 is fixed. The following rectifies this by noting in gimplify_compound_lval when the base object which we gimplify first ends up being a register. * gimplify.cc (gimplify_compound_lval): When the base gimplified to a register make sure to split up chains of operations. Diff: --- gcc/gimplify.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 5a8340504d0..c38a962dd04 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -3281,15 +3281,21 @@ gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, if (need_non_reg && (fallback & fb_rvalue)) prepare_gimple_addressable (p, pre_p); + /* Step 3: gimplify size expressions and the indices and operands of - ARRAY_REF. During this loop we also remove any useless conversions. */ + ARRAY_REF. During this loop we also remove any useless conversions. + If we operate on a register also make sure to properly gimplify + to individual operations. */ + bool reg_operations = is_gimple_reg (*p); for (; expr_stack.length () > 0; ) { tree t = expr_stack.pop (); if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) { + gcc_assert (!reg_operations); + /* Gimplify the low bound and element type size. */ tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p, is_gimple_reg, fb_rvalue); @@ -3306,10 +3312,18 @@ gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, } else if (TREE_CODE (t) == COMPONENT_REF) { + gcc_assert (!reg_operations); + tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p, is_gimple_reg, fb_rvalue); ret = MIN (ret, tret); } + else if (reg_operations) + { + tret = gimplify_expr (&TREE_OPERAND (t, 0), pre_p, post_p, + is_gimple_val, fb_rvalue); + ret = MIN (ret, tret); + } STRIP_USELESS_TYPE_CONVERSION (TREE_OPERAND (t, 0));