From patchwork Wed Feb 28 13:08: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: 207853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3333457dyb; Wed, 28 Feb 2024 05:09:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVQCNNXlzMc1qjXzOpmzWwRGIP/DWM22skkEFLcD+sHS9jPo80jTLka8sIoJsmH5ZBwxDwZ2TPNwvbbTjDlHfhsc5IkIw== X-Google-Smtp-Source: AGHT+IEagamUUT5Lj6l3x2JIpI34Tpw0dQWTh6PQ3qOJnXLf/uYgj5+d+20otPnixeWswXl0ftGH X-Received: by 2002:a05:6359:4287:b0:17b:8a02:a9b6 with SMTP id kp7-20020a056359428700b0017b8a02a9b6mr15258194rwb.21.1709125792242; Wed, 28 Feb 2024 05:09:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709125792; cv=pass; d=google.com; s=arc-20160816; b=nkHTv8X0jKn50dCPIetqhUvnelFXs1sFznpuA8kWwKgL+qOeVSjdcKiyt6a3eDkBDY cW0CW/bKU0jRB7Vk1sXIZaNFb4HsqvyKrt37iSLsacpi5VNRroc4ytq7e60niC7OCZ00 WiaZr+HNdIBIx6NKC1u7y/ZhlSwprOiB+ieYuni7hkAstfLJbj4g4Zflqo5eYDZd/uJF wVqXdEC5JCR1TnCW3hnYhZ13JA1l91FI3QLQ6POC5Qjg4VdDgFPXwOtDMtIfvwJmcw4d 57ZokprIRP5QrB0ITlxGUTXVC5tNvMAsW1td81cb6E6KvvVHDrS7c+EzWTZqgevwhVjh BlmQ== 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=VYFcFx42j2HJlZQQUD59WS8DGLVi5PBvLL7gbeFBJZc=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=QWNcQKHxB+vddOlN4QIAZ+l2m0DvIapyOa22AzYg497t5/NlUUDboBj/qNM1jktjSL dtunMp8lQjHYRilAa2DYd16v/fWN37lbyjQ80YqGEZ3pXlqPCRztPhErks+JdCY4DLGR 3p+Tpco20/EZmp9z40QRz/oKms7Gr0jFyQhUkPUsYXGqL92GqeAArdNAiJdexTKA2mdK 6/wn8Z6YREmbqd+kxOHmCKjBqQUB9ES76zCZoBplQ7eCRxPgs5JMra8Gzu39cI+EWYfP 54wXde+a5u1mNnzun7bg7W7dFSNFBf4vvf/cB6WCAYnB0fEFidUdUndNVRe99VsrbMyZ YyVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=P5eIlsxB; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=HHSMmn8x; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e14-20020a05620a208e00b00787b4aa7cf0si9591125qka.170.2024.02.28.05.09.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 05:09:52 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=P5eIlsxB; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=HHSMmn8x; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 E2E71385843E for ; Wed, 28 Feb 2024 13:09:51 +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 0DC6F3858C62 for ; Wed, 28 Feb 2024 13:09:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DC6F3858C62 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 0DC6F3858C62 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=1709125745; cv=none; b=tPPTykrQm1GziZxE/g5AeMiS2n505anuvfzw+5NVId00whSHzlrTke0I3EvezdbPmBRU/JHcnalBtWbNfRkXhn9+lO0z8WM1zisGnsqRTCO8iL0dVh5W4ZEeFRg7sV78P+I5BWnF6uBzFKKQRssWiEDHDSruLNL9n3GtCmO62f4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709125745; c=relaxed/simple; bh=J7K9KAlNdi78PHRNlrL9JvrsGzVATGcOE2c3HaJbCrs=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=JxrFjb0l+/aW4dv8fj7MzLpspcaB6jQuT4s59lJKWcWMT+UBEAypvL3MV5F+n8Xs05JRiw6cIjuykqQ91uzNMDmvPXtnK009ZO3y4y0PI9WcIUrpLy3z62fejb9kVEiL9yhj4FO4BP7YcPvyArfCNpRIlgtwehMmSu/XuEfetIk= 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 DF0401F460 for ; Wed, 28 Feb 2024 13:08:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709125741; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=VYFcFx42j2HJlZQQUD59WS8DGLVi5PBvLL7gbeFBJZc=; b=P5eIlsxByTZJ6YNjJz8PfwEfuJhKKegHKsZvQDFDV2OZJwOW3lHny2IyT8CZIF/UVlUlaw JxZc445kmywsgSYQWAZXeL0Slq43rjIuZQ3gefJtERfyeufE7kCXnSnkAwpv7EIpZZcTuK nMAU1BuRgkSCWtHOwowOKmMMEa0O/yI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709125741; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=VYFcFx42j2HJlZQQUD59WS8DGLVi5PBvLL7gbeFBJZc=; b=HUWV3QP/qlnlYrTyBG8sN61Q+ROKmnJ8zllNMvDxLK1WbPhKlCvYZIhfG0q8rYfI/8E2y9 WHDhYfQmzb8QPbBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709125739; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=VYFcFx42j2HJlZQQUD59WS8DGLVi5PBvLL7gbeFBJZc=; b=HHSMmn8xolDPDg6db9fBEhZFODB2jkTXrfcxoCW7kHJJ9oxf3DM0FSOweccqPLynxcr1BW Uj2qt5pbFB+WV9yJ2oz5AUt05FdDI+h4hnYNNtpzwOJ6qwrFP7RuD/z5sjs4MspJzB8vNj O4T7wsOC1iBgtyVuhcE+HX7iHJAFm58= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709125739; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=VYFcFx42j2HJlZQQUD59WS8DGLVi5PBvLL7gbeFBJZc=; b=rNpDwIAEVphqgM8Pa3H9i7a0k/xU1x7WGerJfZuvUb36hzvc5EIoZ7Cm8GFmPT3oC85DPS TL2ENlpCxv+9UiBg== Date: Wed, 28 Feb 2024 14:08:59 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] tree-optimization/114121 - wrong VN with context sensitive range info MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 2.19 X-Spamd-Result: default: False [2.19 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-0.06)[-0.061]; 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]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-ssa-pre.cc:url,tree-ssa-sccvn.cc:url]; NEURAL_SPAM_SHORT(2.85)[0.952]; 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.6 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: <20240228130951.E2E71385843E@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792148286482531788 X-GMAIL-MSGID: 1792148286482531788 When VN ends up exploiting range-info specifying the ao_ref offset and max_size we have to make sure to reflect this in the hashtable entry for the recorded expression. The PR113831 fix handled the case where we can encode this in the operands themselves but this bug shows the issue is more widespread. So instead of altering the operands the following instead records this extra info that's possibly used, only throwing it away when the value-numbering didn't come up with a non-VARYING value which is an important detail to preserve CSE as opposed to constant folding which is where all cases currently known popped up. With this the original PR113831 fix can be reverted, see 2/2. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/114121 * tree-ssa-sccvn.h (vn_reference_s::offset, vn_reference_s::max_size): New fields. (vn_reference_insert_pieces): Adjust prototype. * tree-ssa-pre.cc (phi_translate_1): Preserve offset/max_size. * tree-ssa-sccvn.cc (vn_reference_eq): Compare offset and size, allow using "don't know" state. (vn_walk_cb_data::finish): Pass along offset/max_size. (vn_reference_lookup_or_insert_for_pieces): Take offset and max_size as argument and use it. (vn_reference_lookup_3): Properly adjust offset and max_size according to the adjusted ao_ref. (vn_reference_lookup_pieces): Initialize offset and max_size. (vn_reference_lookup): Likewise. (vn_reference_lookup_call): Likewise. (vn_reference_insert): Likewise. (visit_reference_op_call): Likewise. (vn_reference_insert_pieces): Take offset and max_size as argument and use it. * gcc.dg/torture/pr114121.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr114121.c | 35 ++++++++++++++++ gcc/tree-ssa-pre.cc | 5 ++- gcc/tree-ssa-sccvn.cc | 55 ++++++++++++++++++++++--- gcc/tree-ssa-sccvn.h | 3 ++ 4 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr114121.c diff --git a/gcc/testsuite/gcc.dg/torture/pr114121.c b/gcc/testsuite/gcc.dg/torture/pr114121.c new file mode 100644 index 00000000000..9a6ddf2957e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr114121.c @@ -0,0 +1,35 @@ +/* { dg-do run { target bitint } } */ + +#if __BITINT_MAXWIDTH__ >= 256 +unsigned a, b, c, d, e; +unsigned _BitInt(256) f; + +__attribute__((noipa)) unsigned short +bswap16 (int t) +{ + return __builtin_bswap16 (t); +} + +void +foo (unsigned z, unsigned _BitInt(512) y, unsigned *r) +{ + unsigned t = __builtin_sub_overflow_p (0, y << 509, f); + z *= bswap16 (t); + d = __builtin_sub_overflow_p (c, 3, (unsigned _BitInt(512)) 0); + unsigned q = z + c + b; + unsigned short n = q >> (8 + a); + *r = b + e + n; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 256 + unsigned x; + foo (8, 2, &x); + if (x != 8) + __builtin_abort (); +#endif + return 0; +} diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc index d29214d04f8..75217f5cde1 100644 --- a/gcc/tree-ssa-pre.cc +++ b/gcc/tree-ssa-pre.cc @@ -1666,8 +1666,9 @@ phi_translate_1 (bitmap_set_t dest, if (!newoperands.exists ()) newoperands = operands.copy (); newref = vn_reference_insert_pieces (newvuse, ref->set, - ref->base_set, ref->type, - newoperands, + ref->base_set, + ref->offset, ref->max_size, + ref->type, newoperands, result, new_val_id); newoperands = vNULL; } diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index c20ad85c743..21123644a5a 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -438,7 +438,7 @@ static void init_vn_nary_op_from_pieces (vn_nary_op_t, unsigned int, enum tree_code, tree, tree *); static tree vn_lookup_simplify_result (gimple_match_op *); static vn_reference_t vn_reference_lookup_or_insert_for_pieces - (tree, alias_set_type, alias_set_type, tree, + (tree, alias_set_type, alias_set_type, poly_int64, poly_int64, tree, vec, tree); /* Return whether there is value numbering information for a given SSA name. */ @@ -748,6 +748,8 @@ vn_reference_compute_hash (const vn_reference_t vr1) vn_reference_op_compute_hash (vro, hstate); } } + /* Do not hash vr1->offset or vr1->max_size, we want to get collisions + to be able to identify compatible results. */ result = hstate.end (); /* ??? We would ICE later if we hash instead of adding that in. */ if (vr1->vuse) @@ -772,6 +774,16 @@ vn_reference_eq (const_vn_reference_t const vr1, const_vn_reference_t const vr2) if (vr1->vuse != vr2->vuse) return false; + /* The offset/max_size used for the ao_ref during lookup has to be + the same. */ + if (maybe_ne (vr1->offset, vr2->offset) + || maybe_ne (vr1->max_size, vr2->max_size)) + { + /* But nothing known in the prevailing entry is OK to be used. */ + if (maybe_ne (vr1->offset, 0) || known_size_p (vr1->max_size)) + return false; + } + /* If the operands are the same we are done. */ if (vr1->operands == vr2->operands) return true; @@ -2076,6 +2088,7 @@ vn_walk_cb_data::finish (alias_set_type set, alias_set_type base_set, tree val) vec &operands = saved_operands.exists () ? saved_operands : vr->operands; return vn_reference_lookup_or_insert_for_pieces (last_vuse, set, base_set, + vr->offset, vr->max_size, vr->type, operands, val); } @@ -2552,6 +2565,8 @@ static vn_reference_t vn_reference_lookup_or_insert_for_pieces (tree vuse, alias_set_type set, alias_set_type base_set, + poly_int64 offset, + poly_int64 max_size, tree type, vec operands, @@ -2565,15 +2580,18 @@ vn_reference_lookup_or_insert_for_pieces (tree vuse, vr1.type = type; vr1.set = set; vr1.base_set = base_set; + vr1.offset = offset; + vr1.max_size = max_size; vr1.hashcode = vn_reference_compute_hash (&vr1); if (vn_reference_lookup_1 (&vr1, &result)) return result; + if (TREE_CODE (value) == SSA_NAME) value_id = VN_INFO (value)->value_id; else value_id = get_or_alloc_constant_value_id (value); - return vn_reference_insert_pieces (vuse, set, base_set, type, - operands.copy (), value, value_id); + return vn_reference_insert_pieces (vuse, set, base_set, offset, max_size, + type, operands.copy (), value, value_id); } /* Return a value-number for RCODE OPS... either by looking up an existing @@ -3771,6 +3789,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, return (void *)-1; } *ref = r; + vr->offset = r.offset; + vr->max_size = r.max_size; /* Do not update last seen VUSE after translating. */ data->last_vuse_ptr = NULL; @@ -3959,6 +3979,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, if (maybe_ne (ref->size, r.size)) return (void *)-1; *ref = r; + vr->offset = r.offset; + vr->max_size = r.max_size; /* Do not update last seen VUSE after translating. */ data->last_vuse_ptr = NULL; @@ -4023,6 +4045,10 @@ vn_reference_lookup_pieces (tree vuse, alias_set_type set, vr1.type = type; vr1.set = set; vr1.base_set = base_set; + /* We can pretend there's no extra info fed in since the ao_refs offset + and max_size are computed only from the VN reference ops. */ + vr1.offset = 0; + vr1.max_size = -1; vr1.hashcode = vn_reference_compute_hash (&vr1); if ((cst = fully_constant_vn_reference_p (&vr1))) return cst; @@ -4149,6 +4175,8 @@ vn_reference_lookup (tree op, tree vuse, vn_lookup_kind kind, ao_ref_init (&op_ref, op); vr1.set = ao_ref_alias_set (&op_ref); vr1.base_set = ao_ref_base_alias_set (&op_ref); + vr1.offset = 0; + vr1.max_size = -1; vr1.hashcode = vn_reference_compute_hash (&vr1); if (mask == NULL_TREE) if (tree cst = fully_constant_vn_reference_p (&vr1)) @@ -4171,7 +4199,13 @@ vn_reference_lookup (tree op, tree vuse, vn_lookup_kind kind, if (!valueized_anything || !ao_ref_init_from_vn_reference (&r, vr1.set, vr1.base_set, vr1.type, ops_for_ref)) - ao_ref_init (&r, op); + { + ao_ref_init (&r, op); + /* Record the extra info we're getting from the full ref. */ + ao_ref_base (&r); + vr1.offset = r.offset; + vr1.max_size = r.max_size; + } vn_walk_cb_data data (&vr1, r.ref ? NULL_TREE : op, last_vuse_ptr, kind, tbaa_p, mask, redundant_store_removal_p); @@ -4227,6 +4261,8 @@ vn_reference_lookup_call (gcall *call, vn_reference_t *vnresult, vr->punned = false; vr->set = 0; vr->base_set = 0; + vr->offset = 0; + vr->max_size = -1; vr->hashcode = vn_reference_compute_hash (vr); vn_reference_lookup_1 (vr, vnresult); } @@ -4290,6 +4326,10 @@ vn_reference_insert (tree op, tree result, tree vuse, tree vdef) ao_ref_init (&op_ref, op); vr1->set = ao_ref_alias_set (&op_ref); vr1->base_set = ao_ref_base_alias_set (&op_ref); + /* Specifically use an unknown extent here, we're not doing any lookup + and assume the caller didn't either (or it went VARYING). */ + vr1->offset = 0; + vr1->max_size = -1; vr1->hashcode = vn_reference_compute_hash (vr1); vr1->result = TREE_CODE (result) == SSA_NAME ? SSA_VAL (result) : result; vr1->result_vdef = vdef; @@ -4332,7 +4372,8 @@ vn_reference_insert (tree op, tree result, tree vuse, tree vdef) vn_reference_t vn_reference_insert_pieces (tree vuse, alias_set_type set, - alias_set_type base_set, tree type, + alias_set_type base_set, + poly_int64 offset, poly_int64 max_size, tree type, vec operands, tree result, unsigned int value_id) @@ -4349,6 +4390,8 @@ vn_reference_insert_pieces (tree vuse, alias_set_type set, vr1->punned = false; vr1->set = set; vr1->base_set = base_set; + vr1->offset = offset; + vr1->max_size = max_size; vr1->hashcode = vn_reference_compute_hash (vr1); if (result && TREE_CODE (result) == SSA_NAME) result = SSA_VAL (result); @@ -5867,6 +5910,8 @@ visit_reference_op_call (tree lhs, gcall *stmt) vr2->type = vr1.type; vr2->punned = vr1.punned; vr2->set = vr1.set; + vr2->offset = vr1.offset; + vr2->max_size = vr1.max_size; vr2->base_set = vr1.base_set; vr2->hashcode = vr1.hashcode; vr2->result = lhs; diff --git a/gcc/tree-ssa-sccvn.h b/gcc/tree-ssa-sccvn.h index 8ec1de02d30..82f6f7323f9 100644 --- a/gcc/tree-ssa-sccvn.h +++ b/gcc/tree-ssa-sccvn.h @@ -145,6 +145,8 @@ typedef struct vn_reference_s tree vuse; alias_set_type set; alias_set_type base_set; + poly_int64 offset; + poly_int64 max_size; tree type; unsigned punned : 1; vec operands; @@ -268,6 +270,7 @@ tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *, bool, tree * = NULL, tree = NULL_TREE, bool = false); void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t); vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, alias_set_type, + poly_int64, poly_int64, tree, vec, tree, unsigned int); void print_vn_reference_ops (FILE *, const vec); From patchwork Wed Feb 28 13:09:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 207854 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3333616dyb; Wed, 28 Feb 2024 05:10:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWfERcxnjJwkWPJt89HGmDIhhiXD73zTokBNNN6dTs0/Cm0U/8vQoj2YOj7VDQBsYrDczKjoUVqrM7psBgHqlY/5e1wNA== X-Google-Smtp-Source: AGHT+IGyHqmHjFoYkPxcM45POfjC6W5t1Jy9OSdGhFQ8YbEbj2vUxrbHb+8KStEOZKKxPsTF+pxg X-Received: by 2002:a05:622a:1652:b0:42e:7e40:64d3 with SMTP id y18-20020a05622a165200b0042e7e4064d3mr9623880qtj.47.1709125807088; Wed, 28 Feb 2024 05:10:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709125807; cv=pass; d=google.com; s=arc-20160816; b=fkTl8wMsKta2vLOoNtp9N1Qrjr6i+UIuERnuvZkvJo3fBiTO16S6xDtQ76kKrnW7V1 pUGSuetR0KTHkJ5gSBTf97yMIafcXg+Sq2y1R0WdFJZ6s78zSklTZKfh0CLpEI1wgi2l H2rrH9uXja/ZviC/QKb0rkC9gkZmdNRBtarJ0ZG9tiTUK3qWu5ypArY6iJLlb+8hYfAr ydiWjd7F5oqSofLgFANHwGW2PXFmzcbAzhumJJw23eASPx+0HYFTBM7Z4s7SjpTDnKZR yy5P4qp48iWA+78z5l5pJTNAdMeDEQslFXN48hVjxwARz28M/5z71lTOfXp1mdf37UXR FrGg== 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=HE376U9t6++KDG01RU6pEnRNQoFYiFpwhQc8ajXtyY0=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=NtcDVc2JWxmB/6UOGwD8vTiShqTJM4fMmtx583WBKhJz0vBUT6moaOidnVKvSemHez sIQDDyRHqaFmWwv9PqPw28qGjOH6pOvRJcCNsH+9IPF4P51VZe8YlJIgL/pP8B19Z+7F WMJzlGCElRQldKACm9JtcrQ3kFyAysC3qoENWQzJuPRJGTGw3uNoX37gXpdYIyZBjbzQ M1LhMH7YoMfXYlWeL3Zu7BcrrrI3yUkalwJqR66E4WOiAr22vYxiwAIwOoQ3nBo27bVj KycuDcsHX+CyaR1FoBL+qDttM/tKDj2fujvQv2xIe1ff6pH/k8ADLw8Z44z8sew5SVbb bQtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=eVLFWqiV; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=TZEJgP5u; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u13-20020a05620a022d00b007879b1a3f98si9283263qkm.484.2024.02.28.05.10.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 05:10:07 -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=eVLFWqiV; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=TZEJgP5u; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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 C521D3858419 for ; Wed, 28 Feb 2024 13:10:06 +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 4C3003858408 for ; Wed, 28 Feb 2024 13:09:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C3003858408 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 4C3003858408 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=1709125762; cv=none; b=IDnTU91Au9tjABUzN+c+C4OdDi90xBjrrqV3kQqfo/X2Ika/c5T1WU2x+cWTo5PHRef2StOhVRXxyOrULUmclYIGFrPk7BvAY6KahjW1jf/MBySugyPhC7/lTmNVmAYhq3hd8UPzG7heOV7AibGwr9y4JbEppcwMisqdsAQerPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709125762; c=relaxed/simple; bh=qZtIwZlnIARX+X62v7NxCHl1CZivw1PJILyjTVL4q7g=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=gQWIn9rVfvT8siRc1h9wXH/j82IySrQ2VbNsRgdSXKOOjkJQOZo0BkJ/rZeFT/itWAyLPKv7e0t/XWjRQR7/p+5NiqyvPNsglZXuwBqlmrQ3XHu7ikHxV1iJXa1qQzJ+ICwDrpgspCOOfu+GLw6uKWk+KHCPv1AqhiRhPnnE2sc= 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 3D75F1F795 for ; Wed, 28 Feb 2024 13:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709125759; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HE376U9t6++KDG01RU6pEnRNQoFYiFpwhQc8ajXtyY0=; b=eVLFWqiV70oGbtWU/vUDlHvt+1B4mSz4dUatttPjEUnTDV37c+wYoH73AOhSCsPnDLFlWP 1HQel78K+6TYeMUJUQ+enXr7mJb+1hS8JtdK310hO3JdnJ3e8UkmJNAr5GULnhauUYxzeA Mu8H0e3Sh+CFz8GGedUOznfUwkVobGI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709125759; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HE376U9t6++KDG01RU6pEnRNQoFYiFpwhQc8ajXtyY0=; b=DKrJAbS2PnaV1LAwoVtn7KdwT9mg2j98jh79ZzLO0STSdm+XK9ozbLRjwceR3o+W2IaLFZ 4/0iRKAtmZxondBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709125757; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HE376U9t6++KDG01RU6pEnRNQoFYiFpwhQc8ajXtyY0=; b=TZEJgP5u1oLvVvYedG3+tSVIoGkRDqYcBZnDOt0J9luDi4qhrLXAJHWPgPwGIlEj/Cd5pC 10eCHFgjHLvMC9ge4dkS+VII0HyjeHTaoK7w5E826lOrYWURe3u5kpwxkqODXj50tDzjsC 81jppaVO6rE4BgmEnv8UsmnRuMkU9x0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709125757; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HE376U9t6++KDG01RU6pEnRNQoFYiFpwhQc8ajXtyY0=; b=kf1rSyeL091G++HjTsIQepgBd6iylWxZOA4IBr36HRSSdOcPG/Fo338tDbotv9YgGJ7+CH NO4rcyFxPMVFs9Dw== Date: Wed, 28 Feb 2024 14:09:17 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] tree-optimization/113831 - revert original fix MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-0.60 / 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]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-ssa-sccvn.cc:url]; 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-Level: X-Spam-Score: -0.60 X-Spam-Status: No, score=-10.6 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: <20240228131006.C521D3858419@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792148302180524872 X-GMAIL-MSGID: 1792148302180524872 This reverts the original fix for PR113831 which is better fixed by the PR114121 fix. I've XFAILed instead of removing the PR108355 testcase again. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/113831 PR tree-optimization/108355 * tree-ssa-sccvn.cc (copy_reference_ops_from_ref): Revert PR113831 fix. * gcc.dg/tree-ssa/ssa-fre-104.c: XFAIL. --- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c | 2 +- gcc/tree-ssa-sccvn.cc | 134 -------------------- 2 files changed, 1 insertion(+), 135 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c index f0f12ef82b7..425c32dd93c 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c @@ -21,4 +21,4 @@ int main() { *c = &d; } -/* { dg-final { scan-tree-dump-not "foo" "fre1" } } */ +/* { dg-final { scan-tree-dump-not "foo" "fre1" { xfail *-*-* } } } */ diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 21123644a5a..0b7fb0663c7 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -912,8 +912,6 @@ copy_reference_ops_from_ref (tree ref, vec *result) { /* For non-calls, store the information that makes up the address. */ tree orig = ref; - unsigned start = result->length (); - bool seen_variable_array_ref = false; while (ref) { vn_reference_op_s temp; @@ -1000,12 +998,6 @@ copy_reference_ops_from_ref (tree ref, vec *result) tree eltype = TREE_TYPE (TREE_TYPE (TREE_OPERAND (ref, 0))); /* Record index as operand. */ temp.op0 = TREE_OPERAND (ref, 1); - /* When the index is not constant we have to apply the same - logic as get_ref_base_and_extent which eventually uses - global ranges to refine the overall ref extent. Record - we've seen such a case, fixup below. */ - if (TREE_CODE (temp.op0) == SSA_NAME) - seen_variable_array_ref = true; /* Always record lower bounds and element size. */ temp.op1 = array_ref_low_bound (ref); /* But record element size in units of the type alignment. */ @@ -1098,132 +1090,6 @@ copy_reference_ops_from_ref (tree ref, vec *result) else ref = NULL_TREE; } - poly_int64 offset, size, max_size; - tree base; - bool rev; - if (seen_variable_array_ref - && handled_component_p (orig) - && (base = get_ref_base_and_extent (orig, - &offset, &size, &max_size, &rev)) - && known_size_p (max_size) - && known_eq (size, max_size)) - { - poly_int64 orig_offset = offset; - poly_int64 tem; - if (TREE_CODE (base) == MEM_REF - && mem_ref_offset (base).to_shwi (&tem)) - offset += tem * BITS_PER_UNIT; - HOST_WIDE_INT coffset = offset.to_constant (); - /* When get_ref_base_and_extent computes an offset constrained to - a constant position we have to fixup variable array indexes in - the ref to avoid the situation where based on context we'd have - to value-number the same vn_reference ops differently. Make - the vn_reference ops differ by adjusting those indexes to - appropriate constants. */ - poly_int64 off = 0; - bool oob_index = false; - for (unsigned i = result->length (); i > start; --i) - { - auto &op = (*result)[i-1]; - if (flag_checking - && op.opcode == ARRAY_REF - && TREE_CODE (op.op0) == INTEGER_CST) - { - /* The verifier below chokes on inconsistencies of handling - out-of-bound accesses so disable it in that case. */ - tree atype = (*result)[i].type; - if (TREE_CODE (atype) == ARRAY_TYPE) - if (tree dom = TYPE_DOMAIN (atype)) - if ((TYPE_MIN_VALUE (dom) - && TREE_CODE (TYPE_MIN_VALUE (dom)) == INTEGER_CST - && (wi::to_widest (op.op0) - < wi::to_widest (TYPE_MIN_VALUE (dom)))) - || (TYPE_MAX_VALUE (dom) - && TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST - && (wi::to_widest (op.op0) - > wi::to_widest (TYPE_MAX_VALUE (dom))))) - oob_index = true; - } - if ((op.opcode == ARRAY_REF - || op.opcode == ARRAY_RANGE_REF) - && TREE_CODE (op.op0) == SSA_NAME) - { - /* There's a single constant index that get's 'off' closer - to 'offset'. */ - unsigned HOST_WIDE_INT elsz - = tree_to_uhwi (op.op2) * vn_ref_op_align_unit (&op); - unsigned HOST_WIDE_INT idx - = (coffset - off.to_constant ()) / BITS_PER_UNIT / elsz; - if (idx == 0) - op.op0 = op.op1; - else - op.op0 = wide_int_to_tree (TREE_TYPE (op.op0), - wi::to_poly_wide (op.op1) + idx); - op.off = idx * elsz; - off += op.off * BITS_PER_UNIT; - } - else - { - if (op.opcode == ERROR_MARK) - /* two-ops codes have the offset in the first op. */ - ; - else if (op.opcode == ADDR_EXPR - || op.opcode == SSA_NAME - || op.opcode == CONSTRUCTOR - || TREE_CODE_CLASS (op.opcode) == tcc_declaration - || TREE_CODE_CLASS (op.opcode) == tcc_constant) - /* end-of ref. */ - gcc_assert (i == result->length ()); - else if (op.opcode == COMPONENT_REF) - { - /* op.off is tracked in bytes, re-do it manually - because of bitfields. */ - tree field = op.op0; - /* We do not have a complete COMPONENT_REF tree here so we - cannot use component_ref_field_offset. Do the interesting - parts manually. */ - tree this_offset = DECL_FIELD_OFFSET (field); - if (op.op1 || !poly_int_tree_p (this_offset)) - gcc_unreachable (); - else - { - poly_offset_int woffset - = (wi::to_poly_offset (this_offset) - << LOG2_BITS_PER_UNIT); - woffset += wi::to_offset (DECL_FIELD_BIT_OFFSET (field)); - off += woffset.force_shwi (); - } - } - else - { - gcc_assert (known_ne (op.off, -1) - /* The constant offset can be -1. */ - || op.opcode == MEM_REF - /* Out-of-bound indices can compute to - a known -1 offset. */ - || ((op.opcode == ARRAY_REF - || op.opcode == ARRAY_RANGE_REF) - && poly_int_tree_p (op.op0) - && poly_int_tree_p (op.op1) - && TREE_CODE (op.op2) == INTEGER_CST)); - off += op.off * BITS_PER_UNIT; - } - } - } - if (flag_checking && !oob_index) - { - ao_ref r; - if (start != 0) - ; - else if (ao_ref_init_from_vn_reference (&r, 0, 0, TREE_TYPE (orig), - *result)) - gcc_assert (known_eq (r.offset, orig_offset) - && known_eq (r.size, size) - && known_eq (r.max_size, max_size)); - else - gcc_unreachable (); - } - } } /* Build a alias-oracle reference abstraction in *REF from the vn_reference