From patchwork Thu Feb 1 14:20:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 85135 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 3A12A3858005 for ; Thu, 1 Feb 2024 14:21:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 2658F3858C2C for ; Thu, 1 Feb 2024 14:21:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2658F3858C2C 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 2658F3858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706797263; cv=none; b=q4W052M/ZbZ9Udj50rlu80t1+XUcYjwPzNH0O7TdPtsRrEmdWwqZej5N9dCGTIcHgxnTmCImMaqGTz/Gh1UyF3Pv1xkeXr1F4niZ7HnSrGW/Qgw5e2bzJp6xkLS5P1fPoxAQJN+cCJqXStCjZHZB8Dp6Xm2m6wZFXuu/wjtg7/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706797263; c=relaxed/simple; bh=5buFVQzfpvUlvUf/EbUyAXOk7LLKMMGPOGO8QTSzuo4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=NT0h+Vw6F7mSjOxth2ZUcKeSXy3sARg3UXGUZRrFOxn7tdgdJAmEzYsyLlcxklA6lTfGRVTDneRnwciYRLonX3iYdAKZX3eOagxPQguvO90THKdbWDPPo/zNwzL7AYwjXR4O2cNvdo0jjXTtdcQwneEy5CWKtAnEK/veSGte0M0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 4BFC71FBB3 for ; Thu, 1 Feb 2024 14:20:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706797259; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=EqqdQ4kZbYbt9CD0EQuxPRQ7O1UwA/NhtJNxPM0YlgQ=; b=EVp4NFJj0wQ6YSO+X3S/jpZI0CzMQLJ0RUlGGDT5Z6JGfwICky7X3YGBSdrT5SFXKyuGMe XTyfljKZdG5fCZz37HAqRPLVN3MhfNjHKSh7nbKo/tJYPB02pVwDvwNc7P8CaXtgQlVCq+ ybvZ4t2TIaK9/eUmFAdIcQ1A1eBqSVI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706797259; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=EqqdQ4kZbYbt9CD0EQuxPRQ7O1UwA/NhtJNxPM0YlgQ=; b=k4vy7uJeDg8afmC2haLdLMgnB/DUDnvuz2thZcFXMR47sgPO6gqRm8DiWLxbPwb23W52zd qKmsxdVIc8NV3EBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706797259; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=EqqdQ4kZbYbt9CD0EQuxPRQ7O1UwA/NhtJNxPM0YlgQ=; b=EVp4NFJj0wQ6YSO+X3S/jpZI0CzMQLJ0RUlGGDT5Z6JGfwICky7X3YGBSdrT5SFXKyuGMe XTyfljKZdG5fCZz37HAqRPLVN3MhfNjHKSh7nbKo/tJYPB02pVwDvwNc7P8CaXtgQlVCq+ ybvZ4t2TIaK9/eUmFAdIcQ1A1eBqSVI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706797259; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=EqqdQ4kZbYbt9CD0EQuxPRQ7O1UwA/NhtJNxPM0YlgQ=; b=k4vy7uJeDg8afmC2haLdLMgnB/DUDnvuz2thZcFXMR47sgPO6gqRm8DiWLxbPwb23W52zd qKmsxdVIc8NV3EBQ== Date: Thu, 1 Feb 2024 15:20:59 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] rtl-optimization/113255 - avoid re-associating REG_POINTER MINUS MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [2.40 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.00)[15.96%] X-Spam-Score: 2.40 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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+patchwork=sourceware.org@gcc.gnu.org Message-Id: <20240201142142.3A12A3858005@sourceware.org> The following avoids re-associating (minus:DI (reg/f:DI 119) (minus:DI (reg/f:DI 120) (reg/f:DI 114))) into (minus:DI (plus:DI (reg/f:DI 114) (reg/f:DI 119)) (reg/f:DI 120)) as that possibly confuses the REG_POINTER heuristics of RTL alias analysis. This happens to miscompile the PRs testcase during DSE which expands addresses via CSELIB which eventually simplifies what it substituted to. The original code does the innocent ptr - (ptr2 - ptr2'), bias a pointer by the difference of two other pointers. --- This is what I propose for the PR for branches, I have not made much progress with fixing the fallout on the RTL alias analysis change on trunk, so this is the alternative if we decide to revert that. Bootstrapped and tested on x86_64-unknown-linux-gnu on the gcc-13 branch, bootstrapped after reverting of the previous fix on x86_64-unknown-linux-gnu on trunk, testing is still ongoing there. OK? Any preference for trunk? Thanks, Richard. PR rtl-optimization/113255 * simplify-rtx.cc (simplify_context::simplify_binary_operation_1): Do not re-associate a MINUS with a REG_POINTER op0. --- gcc/simplify-rtx.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc index ee75079917f..0108d0aa3bd 100644 --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -3195,11 +3195,15 @@ simplify_context::simplify_binary_operation_1 (rtx_code code, canonicalize (minus A (plus B C)) to (minus (minus A B) C). Don't use the associative law for floating point. The inaccuracy makes it nonassociative, - and subtle programs can break if operations are associated. */ + and subtle programs can break if operations are associated. + Don't use the associative law when subtracting a MINUS from + a REG_POINTER as that can trick find_base_term into discovering + the wrong base. */ if (INTEGRAL_MODE_P (mode) && (plus_minus_operand_p (op0) - || plus_minus_operand_p (op1)) + || ((!REG_P (op0) || !REG_POINTER (op0)) + && plus_minus_operand_p (op1))) && (tem = simplify_plus_minus (code, mode, op0, op1)) != 0) return tem;