From patchwork Wed Jan 31 11:29:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 194699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1823073dyb; Wed, 31 Jan 2024 03:35:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtYZ4mSKAUjfjhg7uttPZNPQdTLhY0ecslOIhWcxoiwyn45n30uMqVfvJHkuwyMaY03ICH X-Received: by 2002:a67:c584:0:b0:469:99df:cb28 with SMTP id h4-20020a67c584000000b0046999dfcb28mr946331vsk.34.1706700930549; Wed, 31 Jan 2024 03:35:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706700930; cv=pass; d=google.com; s=arc-20160816; b=Tv6F7FVBssDc/OAi8/x+s63cCdPPZAr9CXbzdl7IaW/XnFrxhtsmVJ80KamEjwVkZg lySCZ0wI2e3GHIxtkoHK12OfkVgJKFrq+axYWpEliqdOQQspc5stfFvGB7Tfs86/vnYd QVzSmHfJ3skIMbZp89V0IkorGmoeeMY2TZi1TsK21ut3mdCOWT9Po2FQM4GjIy9gVXGg Q2X4vCmqKMgRdeQ2nRX5B4Ki4t/s+ltC0j0Jm6hSW6wM2PyNzVQsDHwqXaie9Qw1TgEw BmKg1JhHsqo5OhJNFI7AFWkNXOAYJCZ/w9UPCa4w4R8duVTV1S8u9TlwwkYO29QvY9iE JxrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :subject:to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=t40MdrZuqUV0X+x8n14qsJqUfUTFkeFyNZ8l3zHyy60=; fh=FXfzv0zSDr9anB3/wTuCaD3iwfefQ5vOOtyebn9hWVI=; b=YMISd4suPsCUWUTLpK3rerxvNWkrBlyk8Ykwsm1Mes6ZF/qpwkf1MGhM7qk8Ar3jmc 7NmKOxue4U9uNWyOXupvsXN54KoXq7gc1s3k9NFdm4BpIeoOiZINYd7Mm1KuvHNY1cLu jWvSrg/Dkk7uBfjBgLTjOKa+/fmlWNGB4zD7ncxLXwa+BwoTiXoWs1qNb3xWl0bpVWp9 ShHbmC9wgRtaGaKhp4sa5/Gu58/Z0KphwDvAeNFE6kiEsvl/DGT8g0n801iKiE6n107e fmXSLXqGn8plOjMg24QAy7Pw4vn0NarPYyzTsEqB1Jg90hrs4ZRWcw3n8zzQKXuKkfxO nHiQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Nl0Nuva5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Nl0Nuva5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="p3vojj/p"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=1; AJvYcCX32pnI203lDCTZBOhUyzu0aGPt5LzZKhPsrJ3DGKc92TTcjraV/upi980vu+euXj4v0P2pnSU26D/AFFnmy+9IxosgvA== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t14-20020ad45bce000000b0068194eb80a5si252413qvt.178.2024.01.31.03.35.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 03:35:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Nl0Nuva5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Nl0Nuva5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="p3vojj/p"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE4513858009 for ; Wed, 31 Jan 2024 11:35:29 +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 67C4A3858D20 for ; Wed, 31 Jan 2024 11:34:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67C4A3858D20 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 67C4A3858D20 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=1706700883; cv=none; b=jjJvrrqH77W8Ic5em73nO9UZYSSHVtGiKrDBrDijaw8x0TkJzlQX1e6ZBTxqzoxUKQCXzMp8I4A5eEcz84pnEy29va6EwjXqe5ipA4oVnGx9ZzbZ2KW62KtSi7ttEzA3M/q89sTeiPejDkbThmY+Oy5nFPjIgClvKLOQbLYrVOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706700883; c=relaxed/simple; bh=JmaeOmYXzwn2IOiFTh3DmWQGkliM2ZwiYUQYky6rZDo=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=ikguDi4B0tvY9rTJFctZerPVb4fjE7kGPFKQSuS+7lqPEGf1w8NtrLUJHoL8vghFRpvZRYYxNVkRfCEb3YF4gREdy+TH9p4DARN65o5E3bAX89lpaTCJZboSoPzAwTvezFjElJ2N4X6/lCOEMV3vC4gcenfw//DF4tnoap3fdvI= 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 342A81FB7B for ; Wed, 31 Jan 2024 11:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706700880; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=t40MdrZuqUV0X+x8n14qsJqUfUTFkeFyNZ8l3zHyy60=; b=Nl0Nuva5ypPXj21bR0cgNI9H/jvjrhO1dopsJNchsR/2oO33xUnLwK+zAi9+exJT7Ce4Ip aWA6fWAytaLWFIs9xujRhNmem8qrSvuMEdrlqcdxOuTREVtcLdEvPrsX6Wv/S1YhyPvt3I 1+m7Kvw7LdrYF0wipbmt2S1hvYyHn3A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706700880; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=t40MdrZuqUV0X+x8n14qsJqUfUTFkeFyNZ8l3zHyy60=; b=p3vojj/phYAa5c9I/fbO3ne1tu64+HeeiVeqsDJguMRsO5iTj4uNVdzUbgprwctP1olnCl EliUqO80ntdgzzBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706700880; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=t40MdrZuqUV0X+x8n14qsJqUfUTFkeFyNZ8l3zHyy60=; b=Nl0Nuva5ypPXj21bR0cgNI9H/jvjrhO1dopsJNchsR/2oO33xUnLwK+zAi9+exJT7Ce4Ip aWA6fWAytaLWFIs9xujRhNmem8qrSvuMEdrlqcdxOuTREVtcLdEvPrsX6Wv/S1YhyPvt3I 1+m7Kvw7LdrYF0wipbmt2S1hvYyHn3A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706700880; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=t40MdrZuqUV0X+x8n14qsJqUfUTFkeFyNZ8l3zHyy60=; b=p3vojj/phYAa5c9I/fbO3ne1tu64+HeeiVeqsDJguMRsO5iTj4uNVdzUbgprwctP1olnCl EliUqO80ntdgzzBg== Date: Wed, 31 Jan 2024 12:29:02 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/113630 - invalid code hoisting MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 5.24 X-Spamd-Result: default: False [5.24 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(2.67)[0.891]; 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]; NEURAL_SPAM_LONG(3.16)[0.904]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] 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+ouuuleilei=gmail.com@gcc.gnu.org Message-Id: <20240131113529.CE4513858009@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789605634519235996 X-GMAIL-MSGID: 1789605634519235996 The following avoids code hoisting (but also PRE insertion) of expressions that got value-numbered to another one that are not a valid replacement (but still compute the same value). This time because the access path ends in a structure with different size, meaning we consider a related access as not trapping because of the size of the base of the access. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/113630 * tree-ssa-pre.cc (compute_avail): Avoid registering a reference with a representation with not matching base access size. * gcc.dg/torture/pr113630.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr113630.c | 4 ++++ gcc/tree-ssa-pre.cc | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr113630.c diff --git a/gcc/testsuite/gcc.dg/torture/pr113630.c b/gcc/testsuite/gcc.dg/torture/pr113630.c new file mode 100644 index 00000000000..72ebdefae27 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr113630.c @@ -0,0 +1,4 @@ +/* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } } */ +/* { dg-additional-options "-fno-strict-aliasing" } */ + +#include "pr110799.c" diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc index e72592de5e5..d29214d04f8 100644 --- a/gcc/tree-ssa-pre.cc +++ b/gcc/tree-ssa-pre.cc @@ -4281,6 +4281,20 @@ compute_avail (function *fun) = wide_int_to_tree (ptr_type_node, wi::to_wide (ref1->op2)); } + /* We also need to make sure that the access path + ends in an access of the same size as otherwise + we might assume an access may not trap while in + fact it might. That's independent of whether + TBAA is in effect. */ + if (TYPE_SIZE (ref1->type) != TYPE_SIZE (ref2->type) + && (! TYPE_SIZE (ref1->type) + || ! TYPE_SIZE (ref2->type) + || ! operand_equal_p (TYPE_SIZE (ref1->type), + TYPE_SIZE (ref2->type)))) + { + operands.release (); + continue; + } operands.release (); result = get_or_alloc_expr_for_reference