From patchwork Tue May 18 08:56:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joern Rennecke X-Patchwork-Id: 1480094 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=Mve0O0ft; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fkqch1QR7z9sVt for ; Tue, 18 May 2021 18:56:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B11C3939C19; Tue, 18 May 2021 08:56:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-vk1-xa2b.google.com (mail-vk1-xa2b.google.com [IPv6:2607:f8b0:4864:20::a2b]) by sourceware.org (Postfix) with ESMTPS id EC3BF3896C1D for ; Tue, 18 May 2021 08:56:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EC3BF3896C1D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joern.rennecke@embecosm.com Received: by mail-vk1-xa2b.google.com with SMTP id f10so971164vkm.12 for ; Tue, 18 May 2021 01:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=Od1XSEBAOZqvUkjLyPb6GObL8MqMuPKdDwM3I6LIyP8=; b=Mve0O0ftxINad3kpVyJBXRVTVFgabP4+7E1Ns/Lnx/l+/UlF+MhAb3rbNes12z4f1b VEAhat8XzloRYjm1E/XuNf8bPej6gWjTVa9DkpYHHE9Sz5JTw0Iwegkw/hLT+c6vQuVi oVDc9LdVmXrDqubOQmYLq0fpMHEtl8L1jybaZABZOSki21/L0skP6sb7qxqek7H2Pxbx jpyEaKzg1Ay3NnxeoX6RB0wz+07GOMJ+/aStCB6zKTtVI4ASTRIfa49N7w/oSf+AUr0a UgsqVKWLDreqoTJmCrIyIuY/Xz2UMi0jCihKZkrqsnjSGokWKL0p4ccTZNj3f8/CGTqj h5OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Od1XSEBAOZqvUkjLyPb6GObL8MqMuPKdDwM3I6LIyP8=; b=gNnIWTGYCJnrieGjVAiY5dzIAws4EdkT7wT/kXuEuhTpLoW2rz89F5TaxfQa2Hw4F8 fIGDFdnAeIG6NxlXerDlQgYWS/VfB3PBh2DUfBbipOHDVG9PMAPI7rL0f2GWkNtPLd7d SNFLzervO2r6qpUTadzuhs/4EvR3sd/reBQqoCE13RHbaMcV36TcmWzenuVgv6in3YAK amy16JPL28eYfhgB19aEQpITrbEiUyP75LJeE7vTuB9Ka0Bo5ZaotV0SONzkhshEekp7 nRXCo6Bzsfx4LVPyr8BM/aTTc2FEnZ1GUtabrS8MZRMwYyBy7JmeSx0AcZrlxMoaOoJH p9KQ== X-Gm-Message-State: AOAM530/mQxiYSt50JXlKqG362e2veGG0IJ6i37IHZUI/VP/CF5ZI9vx WOxUaspAFLwMw6UZbBminFosSyzWbTajxRFuzhU4xFz1Ao8arkXz X-Google-Smtp-Source: ABdhPJwZj3KdJnfeisgfbYNA/kx1t93ZpDGpY6e302498k4Q3ZGPODrkngHGPGldnlw424gSLawModhAXjakgs3QVfk= X-Received: by 2002:a1f:c586:: with SMTP id v128mr4581934vkf.3.1621328206544; Tue, 18 May 2021 01:56:46 -0700 (PDT) MIME-Version: 1.0 From: Joern Rennecke Date: Tue, 18 May 2021 09:56:35 +0100 Message-ID: Subject: RFA: avoid infinite lra loop for constant addresses To: GCC Patches X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" I find that when compiling some files, lra goes into an infinite loop reloading constant addresses. This patch allows them to just be recognized as matching addresses immediately, which also saves a bit of space for a few other files. Bootstrapped and regression tested on x86_64-pc-linux-gnu. gcc/ * lra-constraints.c: New arguments mem_mode and as. Changed caller. If equivalence search has yielded a constant that is valid as an address, use it. diff --git a/gcc/lra-constraints.c b/gcc/lra-constraints.c index a766f1fd7e8..8451da58164 100644 --- a/gcc/lra-constraints.c +++ b/gcc/lra-constraints.c @@ -1454,10 +1454,14 @@ static int curr_swapped; the RTL was changed. if CHECK_ONLY_P is true, check that the *LOC is a correct address - register. Return false if the address register is correct. */ + register. Return false if the address register is correct. + + if MEM_MODE is not VOIDmode, then *LOC is the entire address for a + memory access of MODE in address space AS, and *LOC may be replaced + with a constant if that is a valid address. */ static bool process_addr_reg (rtx *loc, bool check_only_p, rtx_insn **before, rtx_insn **after, - enum reg_class cl) + enum reg_class cl, machine_mode mem_mode, addr_space_t as) { int regno; enum reg_class rclass, new_class; @@ -1502,6 +1506,13 @@ process_addr_reg (rtx *loc, bool check_only_p, rtx_insn **before, rtx_insn **aft if (! check_only_p && (*loc = get_equiv_with_elimination (reg, curr_insn)) != reg) { + /* If the elimination has yielded a constant that is fine as an + address, don't try to reload that. */ + if (CONSTANT_P (*loc) && mem_mode != VOIDmode + && strict_memory_address_addr_space_p + (mem_mode, *loc, as)) + return true; + if (lra_dump_file != NULL) { fprintf (lra_dump_file, @@ -3523,7 +3534,12 @@ process_address_1 (int nop, bool check_only_p, REGNO (*ad.base_term)) != NULL_RTX) ? after : NULL), base_reg_class (ad.mode, ad.as, ad.base_outer_code, - get_index_code (&ad))))) + get_index_code (&ad)), + ((MEM_P (mem) && &XEXP (mem, 0) == ad.base_term) + || (SUBREG_P (op) && MEM_P (SUBREG_REG (op)) + && &XEXP (SUBREG_REG (op), 0) == ad.base_term) + ? ad.mode : VOIDmode), + ad.as))) { change_p = true; if (ad.base_term2 != NULL) @@ -3531,7 +3547,7 @@ process_address_1 (int nop, bool check_only_p, } if (ad.index_term != NULL && process_addr_reg (ad.index_term, check_only_p, - before, NULL, INDEX_REG_CLASS)) + before, NULL, INDEX_REG_CLASS, VOIDmode, ad.as)) change_p = true; /* Target hooks sometimes don't treat extra-constraint addresses as