From patchwork Tue Jul 16 14:45:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1132804 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-505154-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GhSrttWk"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45p39F0BSPz9s4Y for ; Wed, 17 Jul 2019 00:45:35 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=NWAHu97GYGSfTvB13Jj3hHX+OaAbOUHq8sKXA10vLQYEEb1f1WvKM EPEJfwHxO2Zbq+9GcrsE5PUPNfzquVaKx+n2OYw+FbU124XTzUeA8+gBqxzmao3L MwHiSkicxtzjtQWF/T0VnfzsNnTbbxUzjTxv+HWrlNUJZgppA+gihU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=Ey37KR+GnVLA20pvHhADFa2PRQw=; b=GhSrttWk7jF00iRBo1zh 2+0t5yu+SpqhWlkHjySxJWOjd8qNe9GqA2WdVziH9c9UgZxm0wRPqterV0dJdXQt neLT331HE+D1KBasZ/WFPcOau/Vk60WaoiIUAXcsb4JLq0F+FZKaEFnsQMjJbNDg KU5RBNKgLqvl+BRtlXEkvsg= Received: (qmail 73222 invoked by alias); 16 Jul 2019 14:45:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 73154 invoked by uid 89); 16 Jul 2019 14:45:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=ultimately X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 Jul 2019 14:45:15 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B716308FED5 for ; Tue, 16 Jul 2019 14:45:12 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-34.rdu2.redhat.com [10.10.112.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F65D5D71B for ; Tue, 16 Jul 2019 14:45:11 +0000 (UTC) From: Jeff Law Subject: [committed] [PR rtl-optimization/91173] Avoid creating modeless REGs due to simplifiable addresses Openpgp: preference=signencrypt To: gcc-patches Message-ID: <5d4126a9-124b-2edb-f87c-a49786ac370c@redhat.com> Date: Tue, 16 Jul 2019 08:45:10 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 X-IsSubscribed: yes In this BZ we generate a modeless REG and as a result eventually ICE gen_addr_rtx takes a symbol, base, index, step and offset from a MEM_REF and constructs suitable RTL for the address. The caller in question (addr_for_mem_ref) will use expand_expr on the above objects to turn them from trees into suitable RTL. If the base is an SSA_NAME with a constant value (consider we may be compiling with -O1 and fail to propagate away the SSA_NAME), then expand_expr will return the constant rather than a REG, which we pass as base to gen_addr_rtx which will ultimately generate something like (plus (const_int) (const_int)) ^^^ ^^^ base offset Later we want the first argument of the PLUS to be a REG, so we extract the mode from the constant int and use that to generate the REG expression and we've lost because constants are modeless. We could simplify those within gen_addr_rtx. In fact that's precisely what my first patch did. But gen_addr_rtx itself assumes that the form will be (plus (base) (offset)) and will reference the XEXP (addr, 1) which in the case we care about doesn't exist after simplification. That can be worked around with some surgery, but it's actually easier to fix in the caller. So in the caller (addr_for_mem_ref) if we detect that the base, after expansion, is a CONST_INT, we fold it into the offset and set the base to NULL_RTX (gen_addr_rtx is prepared to handle this scenario). This is active in gcc-9 and the trunk, but latent on the older release branches. I'm going to commit to the trunk and backport after suitable soak time. Bootstrapped and regression tested on x86_64, ppc64, ppc64le & sparc (aarch64 failed its comparison test due to an unrelated issue). It's also been regression tested on various *-elf platforms. Jeff commit a0efaa5c1185e6db605c4b16866c9bbbdea8f149 Author: law Date: Tue Jul 16 14:44:44 2019 +0000 PR rtl-optimization/91173 * tree-ssa-address.c (addr_for_mem_ref): If the base is an SSA_NAME with a constant value, fold its value into the offset and clear the base before calling gen_addr_rtx. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@273529 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1eb2797d85f..2bce569e320 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-07-16 Jeff Law + + PR rtl-optimization/91173 + * tree-ssa-address.c (addr_for_mem_ref): If the base is an + SSA_NAME with a constant value, fold its value into the offset + and clear the base before calling gen_addr_rtx. + 2019-07-16 Jakub Jelinek PR rtl-optimization/91164 diff --git a/gcc/tree-ssa-address.c b/gcc/tree-ssa-address.c index e83e1b9296f..8004951d2e8 100644 --- a/gcc/tree-ssa-address.c +++ b/gcc/tree-ssa-address.c @@ -259,6 +259,20 @@ addr_for_mem_ref (struct mem_address *addr, addr_space_t as, ? expand_expr (addr->index, NULL_RTX, pointer_mode, EXPAND_NORMAL) : NULL_RTX); + /* addr->base could be an SSA_NAME that was set to a constant value. The + call to expand_expr may expose that constant. If so, fold the value + into OFF and clear BSE. Otherwise we may later try to pull a mode from + BSE to generate a REG, which won't work with constants because they + are modeless. */ + if (bse && GET_CODE (bse) == CONST_INT) + { + if (off) + off = simplify_gen_binary (PLUS, pointer_mode, bse, off); + else + off = bse; + gcc_assert (GET_CODE (off) == CONST_INT); + bse = NULL_RTX; + } gen_addr_rtx (pointer_mode, sym, bse, idx, st, off, &address, NULL, NULL); if (pointer_mode != address_mode) address = convert_memory_address (address_mode, address);