From patchwork Thu Jun 30 11:32:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 55594 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F20F3842AC8 for ; Thu, 30 Jun 2022 11:34:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F20F3842AC8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1656588853; bh=FwZGYgKFY3vITgF3HVHV5skLD4cPP1+puLZ4MToJ7kg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kptEpeqRVVzflSami/Dg/05M7lV5DDSA0ws5XBzjQsNCe165oxd7jEy3iE0RaEHG6 xcC81bzyuiweE3/IQA0HXyBogJXAyz3zePc9w6oTtihmfD2PS7cFU8oyZcnKABoZny 1Mt0y0R0sSMQ1HbHqGIFb2ORP8rbKDsY2vqEBKmQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 390AD38485A7 for ; Thu, 30 Jun 2022 11:33:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 390AD38485A7 Received: by mail-wm1-x335.google.com with SMTP id c130-20020a1c3588000000b0039c6fd897b4so1484947wma.4 for ; Thu, 30 Jun 2022 04:33:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=FwZGYgKFY3vITgF3HVHV5skLD4cPP1+puLZ4MToJ7kg=; b=1ch67UZdIs9TzlVc5BUCXlsnBX/D4t2dRnASgku4yo7qR2V5+1WNIk4fBWm/v/uEd7 i4qLC7M0Y3axruzsgm7g9N3pcc2sYTbQncU8G5P+0IuCJb5Izuo4tjhouqq4wZ5GRmma aKTZZj7M3TRn+7JDwxan7sFhTwFxmgC4yAXBSGqvG9m791Dr3FlLm+GK38vXAjvgIy6u A8uyXxvUeE1o6c1/GDOkW5DJIu0bX/vJDx4RK3lylvZms7qE77n6Cji7cHYRGCvUu4G+ toHDp1qzKcOGDu+0v4bNwPaAcWcJo1buEqfZeQnuHsVFwgqKqqJ2N5bmf/OhFc6iwqaV wShQ== X-Gm-Message-State: AJIora/cOMn3tLRkc3E46XQsLMoBRqyIG9zHgR5Rb3Z70OUGEWwL4QOv 9DZAFe3guN2BGDCTPmQJuQAMs9gEEoJ+Dw== X-Google-Smtp-Source: AGRyM1uwQEnwpmDL5kaXf96LHkrCf9bWZAxeJKtRS6JYEqMUekcWea7xDpWijLFau5L906tG2MqTrw== X-Received: by 2002:a05:600c:1d03:b0:3a1:7ab1:8dc6 with SMTP id l3-20020a05600c1d0300b003a17ab18dc6mr4501559wms.103.1656588820795; Thu, 30 Jun 2022 04:33:40 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id r23-20020a05600c321700b003a03564a005sm2210362wmp.10.2022.06.30.04.33.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 04:33:40 -0700 (PDT) X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Amend fix for PR middle-end/105874 Date: Thu, 30 Jun 2022 13:32:40 +0200 Message-ID: <2108030.irdbgypaU6@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eric Botcazou via Gcc-patches From: Eric Botcazou Reply-To: Eric Botcazou Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" As pointed out by Richard, it's very likely too big of a hammer. Bootstrapped/regtested on x86-64/Linux, OK for the mainline? 2022-06-30 Eric Botcazou PR middle-end/105874 * expr.cc (expand_expr_real_1) : Force EXPAND_MEMORY for the expansion of the inner reference only in the usual cases where a memory reference is required. diff --git a/gcc/expr.cc b/gcc/expr.cc index c90cde35006..8fb2dc917f7 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -11186,37 +11186,58 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, machine_mode mode1, mode2; poly_int64 bitsize, bitpos, bytepos; tree offset; - int reversep, volatilep = 0, must_force_mem; + int reversep, volatilep = 0; tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1, &unsignedp, &reversep, &volatilep); rtx orig_op0, memloc; bool clear_mem_expr = false; + bool must_force_mem; /* If we got back the original object, something is wrong. Perhaps we are evaluating an expression too early. In any event, don't infinitely recurse. */ gcc_assert (tem != exp); - /* If tem is a VAR_DECL, we need a memory reference. */ - enum expand_modifier tem_modifier = modifier; - if (tem_modifier == EXPAND_SUM) - tem_modifier = EXPAND_NORMAL; - if (TREE_CODE (tem) == VAR_DECL) - tem_modifier = EXPAND_MEMORY; + /* Make sure bitpos is not negative, this can wreak havoc later. */ + if (maybe_lt (bitpos, 0)) + { + gcc_checking_assert (offset == NULL_TREE); + offset = size_int (bits_to_bytes_round_down (bitpos)); + bitpos = num_trailing_bits (bitpos); + } + + /* If we have either an offset, a BLKmode result, or a reference + outside the underlying object, we must force it to memory. + Such a case can occur in Ada if we have unchecked conversion + of an expression from a scalar type to an aggregate type or + for an ARRAY_RANGE_REF whose type is BLKmode, or if we were + passed a partially uninitialized object or a view-conversion + to a larger size. */ + must_force_mem = offset != NULL_TREE + || mode1 == BLKmode + || (mode == BLKmode + && !int_mode_for_size (bitsize, 1).exists ()); + + const enum expand_modifier tem_modifier + = must_force_mem + ? EXPAND_MEMORY + : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier; /* If TEM's type is a union of variable size, pass TARGET to the inner computation, since it will need a temporary and TARGET is known to have to do. This occurs in unchecked conversion in Ada. */ + const rtx tem_target + = TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE + && COMPLETE_TYPE_P (TREE_TYPE (tem)) + && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) != INTEGER_CST + && modifier != EXPAND_STACK_PARM + ? target + : NULL_RTX; + orig_op0 = op0 - = expand_expr_real (tem, - (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE - && COMPLETE_TYPE_P (TREE_TYPE (tem)) - && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) - != INTEGER_CST) - && modifier != EXPAND_STACK_PARM - ? target : NULL_RTX), - VOIDmode, tem_modifier, NULL, true); + = expand_expr_real (tem, tem_target, VOIDmode, tem_modifier, NULL, + true); /* If the field has a mode, we want to access it in the field's mode, not the computed mode. @@ -11233,27 +11254,9 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, mode2 = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0); - /* Make sure bitpos is not negative, it can wreak havoc later. */ - if (maybe_lt (bitpos, 0)) - { - gcc_checking_assert (offset == NULL_TREE); - offset = size_int (bits_to_bytes_round_down (bitpos)); - bitpos = num_trailing_bits (bitpos); - } - - /* If we have either an offset, a BLKmode result, or a reference - outside the underlying object, we must force it to memory. - Such a case can occur in Ada if we have unchecked conversion - of an expression from a scalar type to an aggregate type or - for an ARRAY_RANGE_REF whose type is BLKmode, or if we were - passed a partially uninitialized object or a view-conversion - to a larger size. */ - must_force_mem = (offset - || mode1 == BLKmode - || (mode == BLKmode - && !int_mode_for_size (bitsize, 1).exists ()) - || maybe_gt (bitpos + bitsize, - GET_MODE_BITSIZE (mode2))); + /* See above for the rationale. */ + if (maybe_gt (bitpos + bitsize, GET_MODE_BITSIZE (mode2))) + must_force_mem = true; /* Handle CONCAT first. */ if (GET_CODE (op0) == CONCAT && !must_force_mem) @@ -11311,7 +11314,7 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, } else /* Otherwise force into memory. */ - must_force_mem = 1; + must_force_mem = true; } /* If this is a constant, put it in a register if it is a legitimate