From patchwork Thu Aug 22 15:44:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 1975630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AK1ngQ9x; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=EZmqUv/n; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AK1ngQ9x; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=EZmqUv/n; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WqSFm4TGqz1ybW for ; Fri, 23 Aug 2024 01:45:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 70E953875462 for ; Thu, 22 Aug 2024 15:45:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 725153875430 for ; Thu, 22 Aug 2024 15:44:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 725153875430 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 725153875430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724341486; cv=none; b=KJwcQaPJa47nHvfn7hbTijqMClAhLkr0wzMVUaXZ9pYicsi8OreuplqOd+pLqBsf9p/eJiesMDqTYEt97T68qubni+u4YOLKbUxp9RKDPbdymjz/KvdIonGWXv7Y2+CTlrQbLt4T7POlaFYNNQZRhrM5A0683kbT0Yps8AJ5AwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724341486; c=relaxed/simple; bh=WPOD6SH31jM3Eh3rqAgZZIaA51juYKD6AjWzE/6D48k=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=MwQFEwofqmjqpUlAm95PRHz4ARYZLL21hScqGNKY1cGEm4TwzrMAYltSJoDPLLNx0pj+hPusqWMMb17xdKzsHjOT0YXO6nVyBGVBJFUp6H96NV7TVGNLJCLqCRpwtY8jBDCV4dgQfUJp/0fpaCkfg7o93+qPGLyvn5ZNV4krfmE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from knuth.suse.de (unknown [10.168.5.16]) by smtp-out1.suse.de (Postfix) with ESMTP id 70E19222C3 for ; Thu, 22 Aug 2024 15:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1724341474; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=vFoCCQBjAQ1IE2d5qIxDSQtPv5x8k2oXIJDw5HorAss=; b=AK1ngQ9x2maZZ1DRBKXFrlZ1SAW8M+eay1RwbYpqY9VTFmANV5nrsBugPxvsXUvWDbXKU2 8XHYizVqul4JgEBvxK82mL6SuudDa0GbOv21fzGOP/zWcAQcml4awSh8fpAKMWhpP2dFQy AUOWLBx0DJZTScc8cTZ29s/A8e6Oz7s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1724341474; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=vFoCCQBjAQ1IE2d5qIxDSQtPv5x8k2oXIJDw5HorAss=; b=EZmqUv/n/FvMLAjRXFljICV0nVM8rJZpbc7jDdRIIMeQXd4auC2QudxKPsHXpA3BgJiyRY 1ZJHvPV6g+6PLOAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1724341474; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=vFoCCQBjAQ1IE2d5qIxDSQtPv5x8k2oXIJDw5HorAss=; b=AK1ngQ9x2maZZ1DRBKXFrlZ1SAW8M+eay1RwbYpqY9VTFmANV5nrsBugPxvsXUvWDbXKU2 8XHYizVqul4JgEBvxK82mL6SuudDa0GbOv21fzGOP/zWcAQcml4awSh8fpAKMWhpP2dFQy AUOWLBx0DJZTScc8cTZ29s/A8e6Oz7s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1724341474; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=vFoCCQBjAQ1IE2d5qIxDSQtPv5x8k2oXIJDw5HorAss=; b=EZmqUv/n/FvMLAjRXFljICV0nVM8rJZpbc7jDdRIIMeQXd4auC2QudxKPsHXpA3BgJiyRY 1ZJHvPV6g+6PLOAw== Received: by knuth.suse.de (Postfix, from userid 10510) id 68FC44C5921; Thu, 22 Aug 2024 17:44:34 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by knuth.suse.de (Postfix) with ESMTP id 59C9E4C5920 for ; Thu, 22 Aug 2024 17:44:34 +0200 (CEST) Date: Thu, 22 Aug 2024 17:44:34 +0200 (CEST) From: Michael Matz To: gcc-patches@gcc.gnu.org Subject: LRA: Don't use 0 as initialization for sp_offset Message-ID: MIME-Version: 1.0 X-Spam-Score: -4.20 X-Spamd-Result: default: False [-4.20 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; MID_RHS_MATCH_FROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[]; RECEIVED_HELO_LOCALHOST(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; URIBL_BLOCKED(0.00)[suse.de:mid,lra-eliminations.cc:url,knuth.suse.de:helo]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid] X-Spam-Level: X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org this is part of making m68k work with LRA. See PR116374. m68k has the property that sometimes the elimation offset between %sp and %argptr is zero. During setting up elimination infrastructure it's changes between sp_offset and previous_offset that feed into insns_with_changed_offsets that ultimately will setup looking at the instructions so marked. But the initial values for sp_offset and previous_offset are also zero. So if the targets INITIAL_ELIMINATION_OFFSET (called in update_reg_eliminate) is zero then nothing changes, the instructions in question don't get into the list to consider and the sp_offset tracking goes wrong. Solve this by initializing those member with -1 instead of zero. An initial offset of that value seems very unlikely, as it's in word-sized increments. This then also reveals a problem in eliminate_regs_in_insn where it always uses sp_offset-previous_offset as offset adjustment, even in the first_p pass. That was harmless when previous_offset was uninitialized as zero. But all the other code uses a different idiom of checking for first_p (or rather update_p which is !replace_p&&!first_p), and using sp_offset directly. So use that as well in eliminate_regs_in_insn. PR target/116374 * lra-eliminations.cc (init_elim_table): Use -1 as initializer. (update_reg_eliminate): Accept -1 as not-yet-used marker. (eliminate_regs_in_insn): Use previous_sp_offset only when not first_p. --- gcc/lra-eliminations.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- Regstrapped on x86-64-linux. Okay? diff --git a/gcc/lra-eliminations.cc b/gcc/lra-eliminations.cc index 5bed259cffe..96772f2904a 100644 --- a/gcc/lra-eliminations.cc +++ b/gcc/lra-eliminations.cc @@ -969,7 +969,8 @@ eliminate_regs_in_insn (rtx_insn *insn, bool replace_p, bool first_p, if (! replace_p) { if (known_eq (update_sp_offset, 0)) - offset += (ep->offset - ep->previous_offset); + offset += (!first_p + ? ep->offset - ep->previous_offset : ep->offset); if (ep->to_rtx == stack_pointer_rtx) { if (first_p) @@ -1212,7 +1213,7 @@ update_reg_eliminate (bitmap insns_with_changed_offsets) if (lra_dump_file != NULL) fprintf (lra_dump_file, " Using elimination %d to %d now\n", ep1->from, ep1->to); - lra_assert (known_eq (ep1->previous_offset, 0)); + lra_assert (known_eq (ep1->previous_offset, -1)); ep1->previous_offset = ep->offset; } else @@ -1283,7 +1284,7 @@ init_elim_table (void) for (ep = reg_eliminate, ep1 = reg_eliminate_1; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++, ep1++) { - ep->offset = ep->previous_offset = 0; + ep->offset = ep->previous_offset = -1; ep->from = ep1->from; ep->to = ep1->to; value_p = (targetm.can_eliminate (ep->from, ep->to)