From patchwork Sun Dec 7 02:06:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 126086 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 369AE48F1777 for ; Sun, 7 Dec 2025 02:07:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 369AE48F1777 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=XMb2KoOd X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by sourceware.org (Postfix) with ESMTPS id C742948F3402 for ; Sun, 7 Dec 2025 02:06:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C742948F3402 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C742948F3402 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1765073187; cv=none; b=bv5I9DGLmrqsnF3KVIsUZKAtv72ivzReAgNZF/+4q2aJqQyiNuKRkLEZ+ldB4j/kMlznKjxW6eU5fmzsPS6XlQf9uVJCbUNeH9Mss9moqQF02kXeogkIB3HH3JWebq3Vpw+azfen/MMdlNRvjB1YZd317ARgIiuzWQRiiFGT7Jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1765073187; c=relaxed/simple; bh=iVP8Fd/C/A3oHoG7J7j5LXbrRpeXcr4mEkeBptnw6kw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hGRBXUh2fae4Q1iY4By/EbWiTmzBVDQfHY+vN5oySgPnW6kQKYjZx6Uaiucqc9wF4d6Pb2zgvO2W0neVvm7gNAwvgxhnb9Hn5iHT0Kwh7aP9RnpWJY8dhVvRuQbje8VzSK0cdPwnNbHeh4vr7Y6Wf2NojBo/g3SidiSTYy3PMt4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C742948F3402 Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-bf5ac50827dso2284650a12.2 for ; Sat, 06 Dec 2025 18:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1765073185; x=1765677985; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Mch/8g0Eg6wc7B1SkU0BWyyjpVZjHysUoFrc9PLH7CE=; b=XMb2KoOdpaUivhVNvfuyyQPGUu2WyQP9vnXmy0D4Av0MqKQNwz+kE9vHIYOASdWNNu Xc3olD46iv59tcA0fOGQdkyIyF8HxCGAvnhBLMIMO643agQXGX70t5rvIRxkclwSwbZ1 PIEIU8VySKX4oJUWsUxgswYjmTI+Vih/sehNom/fC56f3OGlkqkEO6FxedcJX6mQtmPu bCmmkTQg86ZtUn2joaRWtbBXanl0EtkKuXvHcXZEfYK6jN9GvofWgEsLvt0YTXMynCrI 9MCD27Heek4mSSNurLdzGS3fEqxd2+0Cr3y7cec2daz9BkrGLYkWFaEjbkGEMAf4QajG t/EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765073185; x=1765677985; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Mch/8g0Eg6wc7B1SkU0B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2ab:c279:9dce with SMTP id 5a478bee46e88-2abc70e7c0bmr2266852eec.7.1765073185207; Sat, 06 Dec 2025 18:06:25 -0800 (PST) Received: from free.home ([2804:14c:4d1:41a6::1455]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2aba8816ae9sm26701411eec.5.2025.12.06.18.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Dec 2025 18:06:24 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 5B7264OW639297 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 6 Dec 2025 23:06:05 -0300 From: Alexandre Oliva To: Eric Botcazou Cc: gcc-patches@gcc.gnu.org, Steven Bosscher Subject: [PATCH v2] cselib: lookup mem addr during invalidation Organization: Free thinker, does not speak for AdaCore References: <2196418.9o76ZdvQCi@fomalhaut> Date: Sat, 06 Dec 2025 23:06:04 -0300 In-Reply-To: <2196418.9o76ZdvQCi@fomalhaut> (Eric Botcazou's message of "Fri, 05 Dec 2025 10:40:50 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 On Dec 5, 2025, Eric Botcazou wrote: >> * cselib.cc (cselib_invalidate_mem): Lookup the address as >> part of canonicalizing it. > The cselib_invalidate_mem change looks a bit risky at this stage ... and here's that part split out for the next stage1. Ok then? When processing stores for e.g. parameters passed on the stack, as in gcc.dg/pr117239.c, each store invalidates other stores pertaining to the same argument, because we can tell they refer to the same object, but not that the offsets don't overlap. The reason for that is that the mem_rtx being invalidated is canonicalized to an SP offset, while those in the cselib table have canonical values as addresses, and alias.cc can't resolve SP to values to compare the offsets. With this change, pr117239.c doesn't require -fschedule-insns to fail, with the PR117239 fixes reverted. for gcc/ChangeLog * cselib.cc (cselib_invalidate_mem): Lookup the address as part of canonicalizing it. --- gcc/cselib.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/cselib.cc b/gcc/cselib.cc index 930357409bc54..c6628abf2a989 100644 --- a/gcc/cselib.cc +++ b/gcc/cselib.cc @@ -2623,6 +2623,14 @@ cselib_invalidate_mem (rtx mem_rtx) rtx mem_addr; mem_addr = canon_rtx (get_addr (XEXP (mem_rtx, 0))); + /* Resolve MEM_ADDR to a VALUE_RTX, so that canon_anti_dependence can compare + offsets from the same base, even for SP-based addresses. */ + if ((v = cselib_lookup (mem_addr, GET_MODE (mem_addr), + 0, GET_MODE (mem_rtx)))) + { + mem_addr = v->val_rtx; + mem_rtx = replace_equiv_address_nv (mem_rtx, mem_addr); + } mem_rtx = canon_rtx (mem_rtx); vp = &first_containing_mem;