Message ID | ZbwfF+oAgCCq002P@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp72398dyc; Thu, 1 Feb 2024 14:46:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1Oz2WlhZu8EDHFwMnB2MXWKU1NcpDyKSE8PYIA/UYFZmMOwKjLlVRRqnYBAPZ3uvRw5hn X-Received: by 2002:ad4:5945:0:b0:68c:68e8:3314 with SMTP id eo5-20020ad45945000000b0068c68e83314mr4165093qvb.63.1706827607225; Thu, 01 Feb 2024 14:46:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706827607; cv=pass; d=google.com; s=arc-20160816; b=0ZrXCa5p6bSMRcc5NRElJrUYPLWQ4SvWsdRe/4dP01q1bCm7tTCd76cdMkhKMIa1Xa hsVZos1J00Vflu6ZhB2/KujA/WGjn4nCe0tjYyFO/fpDwMqaeErBca9Pu1MVtr8x7zjT YcGPyx9G836xvrztPjBQEwxT3QBr/PkLRyW3CUf21HJlbPi+dEUY+6bXtVnpyTrSDRwj 8BxSlCVW9HLWdOQJE/mTtF+gHPCYzTnaFiN1L2uFFgZ1lWuTAFIM5AgqpqdHljngC3Lg Mj95Pj7482CUAVheI3FZazBBFdMlOCOmmF71uaQvlKoIGZhZWLAUqqSW45jdUOonSclP 3ZLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=v2o4fyo+LBuZ0PpG9/kChkriwCGQMn6pOlhcb0jDtEc=; fh=aP6ijWOf05mcPdvTDgyM2ZWpWkv24+rdwS7rrAkiNnY=; b=frU1CteZyzrAyk8f9me7fCwd4HoS+CBoXwm3HBCaOsS/BuRDTghAP8QUGIr0g/bbJu Tax2HAPwc0mAk4P87TGeYJP4j6mZlvKYduAF6UxSSZ0RLKWukFaG86EWYUcKla8W0vog sTutl9wnJfDJk2HLaQHyEDGbz99/SYlMtPLWiHW/vi9yShltwHeY1enrXMOr8iRSOEhF wtRCgqEs5BT4L+dSJkx4kKZsWiIA2E4+1rRnSFvg4F/BevB/lZxeWBS27WFXZ3nHPqj+ NR38djGzOdl2LwntFjactjzbHD3Kn2YLykIbJtPGINKaSiNvJL8CNyr6NM8yA0qB2I/2 hW+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KhuUrhL2; 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=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCVrGdW8d0OW5vtf34ZsGd5B3OmNRqolSqKIqX+IUpNN5v4iS5sWlQwLyqH+2coVAApEMxeL4R2lpWVgHcigY0zZeVNjmQ== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id et8-20020a056214176800b00680f70d3983si583301qvb.117.2024.02.01.14.46.47 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 14:46:47 -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=@redhat.com header.s=mimecast20190719 header.b=KhuUrhL2; 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BD2C43858009 for <ouuuleilei@gmail.com>; Thu, 1 Feb 2024 22:46:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BF1C73858D33 for <gcc-patches@gcc.gnu.org>; Thu, 1 Feb 2024 22:45:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF1C73858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BF1C73858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706827560; cv=none; b=CWNGS3KKkUj7wP+3ZDWC90n407rOapa1TL9yCDeSywh54U2071aJfVD597DM6/I2oHSB601Z+R78cLI/xMaUN8D7MQI+95pGLj/GI68hPq23sVkrTd8rliVyi7k4T6cFivflScYT8HD4dGQYF6xZmDP9G6LlPAL/IlIrXchLUE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706827560; c=relaxed/simple; bh=sIprk1lqep3A9kU2NsFVDd+SoFCcuR2KUiGnpmytwFE=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=dBYwf+c/1NxTNd0SSlrfdjUUbcL7Iw8N0sWwIdyRVz79UUaK7Z9fnmRESNPX+uGMhmcc5JQXg3MO7jPn7enTwD/dHpBurJAHdJFTzi6MGNIU17wEo5wur0cJ6t6MM5y0g5E6imY9C1kyMl4cD5yWkQL7UOjQIrF1kJG7euDgGg8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827555; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=v2o4fyo+LBuZ0PpG9/kChkriwCGQMn6pOlhcb0jDtEc=; b=KhuUrhL2JJPq/XT2bVPi9hECaLSm2Z9Z2ihAdELj6HwYN+jyN7Sh3hVhR/i2yEZf3IMPW6 G+qyqdEpudVenotUhUzYkE2ufLnAkV5cWCCk1zIYsrGbAaoIZjss2gnIZZic2RFPoIK1fT TMAd2F0p/YwC29wTd9MyswS7blk6OC4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-349-byX1VC1OMGWwFdvXvSPiIQ-1; Thu, 01 Feb 2024 17:45:52 -0500 X-MC-Unique: byX1VC1OMGWwFdvXvSPiIQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA68A1C2FE24; Thu, 1 Feb 2024 22:45:51 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 705C32166B33; Thu, 1 Feb 2024 22:45:51 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 411Mjipv2703715 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 1 Feb 2024 23:45:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 411Mjh3C2703714; Thu, 1 Feb 2024 23:45:43 +0100 Date: Thu, 1 Feb 2024 23:45:43 +0100 From: Jakub Jelinek <jakub@redhat.com> To: Richard Biener <rguenther@suse.de>, Jeff Law <jeffreyalaw@gmail.com>, Roger Sayle <roger@nextmovesoftware.com> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-ssa-math-opts: Fix is_widening_mult_rhs_p - unbreak bootstrap [PR113705] Message-ID: <ZbwfF+oAgCCq002P@tucnak> References: <003f01da534e$94918450$bdb48cf0$@nextmovesoftware.com> MIME-Version: 1.0 In-Reply-To: <003f01da534e$94918450$bdb48cf0$@nextmovesoftware.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SOMETLD_ARE_BAD_TLD, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789738465326606161 X-GMAIL-MSGID: 1789738465326606161 |
Series |
tree-ssa-math-opts: Fix is_widening_mult_rhs_p - unbreak bootstrap [PR113705]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Feb. 1, 2024, 10:45 p.m. UTC
On Tue, Jan 30, 2024 at 07:33:10AM -0000, Roger Sayle wrote: + wide_int bits = wide_int::from (tree_nonzero_bits (rhs), + prec, + TYPE_SIGN (TREE_TYPE (rhs))); ... > + if (gimple_assign_rhs_code (stmt) == BIT_AND_EXPR > + && TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST > + && wi::to_wide (gimple_assign_rhs2 (stmt)) > + == wi::mask (hprec, false, prec)) This change broke bootstrap on aarch64-linux. The problem can be seen even on the reduced testcase. The IL on the unreduced testcase before widening_mul has: # val_583 = PHI <val_26(13), val_164(40)> ... pretmp_266 = MEM[(const struct wide_int_storage *)&D.160657].len; _264 = pretmp_266 & 65535; ... _176 = (sizetype) val_583; _439 = (sizetype) _264; _284 = _439 * 8; _115 = _176 + _284; where 583/266/264 have unsigned int type and 176/439/284/115 have sizetype. widening_mul first turns that into: # val_583 = PHI <val_26(13), val_164(40)> ... pretmp_266 = MEM[(const struct wide_int_storage *)&D.160657].len; _264 = pretmp_266 & 65535; ... _176 = (sizetype) val_583; _439 = (sizetype) _264; _284 = _264 w* 8; _115 = _176 + _284; and then is_widening_mult_rhs_p is called, with type sizetype (64-bit), rhs _264, hprec 32 and prec 64. Now tree_nonzero_bits (rhs) is 65535, so bits is 64-bit wide_int 65535, stmt is BIT_AND_EXPR, but we ICE on the wi::to_wide (gimple_assign_rhs2 (stmt)) == wi::mask (hprec, false, prec) comparison because wi::to_wide on gimple_assign_rhs2 (stmt) - unsigned int 65535 gives 32-bit wide_int 65535, while wi::mask (hprec, false, prec) gives 64-bit wide_int 0xffffffff and comparison between different precision wide_ints is forbidden. The following patch fixes it the same way how bits is computed earlier, by calling wide_int::from on the wi::to_wide (gimple_assign_rhs2 (stmt)), so we compare 64-bit 65535 with 64-bit 0xffffffff. Bootstrapped/regtested on x86_64-linux and i686-linux plus tested on the testcase using cross to aarch64-linux, ok for trunk? 2024-02-01 Jakub Jelinek <jakub@redhat.com> PR middle-end/113705 * tree-ssa-math-opts.cc (is_widening_mult_rhs_p): Use wide_int_from around wi::to_wide in order to compare value in prec precision. * g++.dg/opt/pr113705.C: New test. Jakub
Comments
> Am 01.02.2024 um 23:46 schrieb Jakub Jelinek <jakub@redhat.com>: > > On Tue, Jan 30, 2024 at 07:33:10AM -0000, Roger Sayle wrote: > + wide_int bits = wide_int::from (tree_nonzero_bits (rhs), > + prec, > + TYPE_SIGN (TREE_TYPE (rhs))); > ... >> + if (gimple_assign_rhs_code (stmt) == BIT_AND_EXPR >> + && TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST >> + && wi::to_wide (gimple_assign_rhs2 (stmt)) >> + == wi::mask (hprec, false, prec)) > > This change broke bootstrap on aarch64-linux. > The problem can be seen even on the reduced testcase. > > The IL on the unreduced testcase before widening_mul has: > # val_583 = PHI <val_26(13), val_164(40)> > ... > pretmp_266 = MEM[(const struct wide_int_storage *)&D.160657].len; > _264 = pretmp_266 & 65535; > ... > _176 = (sizetype) val_583; > _439 = (sizetype) _264; > _284 = _439 * 8; > _115 = _176 + _284; > where 583/266/264 have unsigned int type and 176/439/284/115 have sizetype. > widening_mul first turns that into: > # val_583 = PHI <val_26(13), val_164(40)> > ... > pretmp_266 = MEM[(const struct wide_int_storage *)&D.160657].len; > _264 = pretmp_266 & 65535; > ... > _176 = (sizetype) val_583; > _439 = (sizetype) _264; > _284 = _264 w* 8; > _115 = _176 + _284; > and then is_widening_mult_rhs_p is called, with type sizetype (64-bit), > rhs _264, hprec 32 and prec 64. Now tree_nonzero_bits (rhs) is > 65535, so bits is 64-bit wide_int 65535, stmt is BIT_AND_EXPR, > but we ICE on the > wi::to_wide (gimple_assign_rhs2 (stmt)) == wi::mask (hprec, false, prec) > comparison because wi::to_wide on gimple_assign_rhs2 (stmt) - unsigned int > 65535 gives 32-bit wide_int 65535, while wi::mask (hprec, false, prec) > gives 64-bit wide_int 0xffffffff and comparison between different precision > wide_ints is forbidden. > > The following patch fixes it the same way how bits is computed earlier, > by calling wide_int::from on the wi::to_wide (gimple_assign_rhs2 (stmt)), > so we compare 64-bit 65535 with 64-bit 0xffffffff. > > Bootstrapped/regtested on x86_64-linux and i686-linux plus tested on the > testcase using cross to aarch64-linux, ok for trunk? Ok Richard > 2024-02-01 Jakub Jelinek <jakub@redhat.com> > > PR middle-end/113705 > * tree-ssa-math-opts.cc (is_widening_mult_rhs_p): Use wide_int_from > around wi::to_wide in order to compare value in prec precision. > > * g++.dg/opt/pr113705.C: New test. > > --- gcc/tree-ssa-math-opts.cc.jj 2024-02-01 09:14:16.623549514 +0100 > +++ gcc/tree-ssa-math-opts.cc 2024-02-01 17:48:59.151771177 +0100 > @@ -2572,7 +2572,8 @@ is_widening_mult_rhs_p (tree type, tree > if (is_gimple_assign (stmt) > && gimple_assign_rhs_code (stmt) == BIT_AND_EXPR > && TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST > - && wi::to_wide (gimple_assign_rhs2 (stmt)) > + && wide_int::from (wi::to_wide (gimple_assign_rhs2 (stmt)), > + prec, TYPE_SIGN (TREE_TYPE (rhs))) > == wi::mask (hprec, false, prec)) > *new_rhs_out = gimple_assign_rhs1 (stmt); > else > --- gcc/testsuite/g++.dg/opt/pr113705.C.jj 2024-02-01 19:02:29.181388575 +0100 > +++ gcc/testsuite/g++.dg/opt/pr113705.C 2024-02-01 19:03:03.211918152 +0100 > @@ -0,0 +1,68 @@ > +// PR middle-end/113705 > +// { dg-do compile { target c++17 } } > +// { dg-options "-O2 -w" } > + > +void foo (); > +template <typename T> struct A : T { long bar () const; }; > +int a; > + > +template <typename T> > +long > +A<T>::bar () const > +{ > + return this->baz ()[a]; > +} > + > +struct B { > + struct { long b[1]; long c; } u; > + unsigned d; > + int e; > + B (const B &); > + ~B (); > + const long *baz () const; > + unsigned qux () const; > +}; > + > +B::B (const B &) > +{ > + if (__builtin_expect (e, 0)) > + u.c = 0; > +} > + > +B::~B () > +{ > + if (__builtin_expect (e, 0)) > + foo (); > +} > + > +const long * > +B::baz () const > +{ > + return u.b; > +} > + > +unsigned > +B::qux () const > +{ > + return d; > +} > + > +struct C { A<B> corge () const; A<B> *f; }; > + > +A<B> > +C::corge () const > +{ > + return f[1]; > +} > + > +void > +test (C r, long *h, unsigned short *d) > +{ > + for (int j = 0; j < 8; ++j) > + { > + A g = r.corge (); > + *d = g.qux (); > + for (unsigned i = 0; i < *d; ++i) > + *h++ = g.bar (); > + } > +} > > > Jakub >
--- gcc/tree-ssa-math-opts.cc.jj 2024-02-01 09:14:16.623549514 +0100 +++ gcc/tree-ssa-math-opts.cc 2024-02-01 17:48:59.151771177 +0100 @@ -2572,7 +2572,8 @@ is_widening_mult_rhs_p (tree type, tree if (is_gimple_assign (stmt) && gimple_assign_rhs_code (stmt) == BIT_AND_EXPR && TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST - && wi::to_wide (gimple_assign_rhs2 (stmt)) + && wide_int::from (wi::to_wide (gimple_assign_rhs2 (stmt)), + prec, TYPE_SIGN (TREE_TYPE (rhs))) == wi::mask (hprec, false, prec)) *new_rhs_out = gimple_assign_rhs1 (stmt); else --- gcc/testsuite/g++.dg/opt/pr113705.C.jj 2024-02-01 19:02:29.181388575 +0100 +++ gcc/testsuite/g++.dg/opt/pr113705.C 2024-02-01 19:03:03.211918152 +0100 @@ -0,0 +1,68 @@ +// PR middle-end/113705 +// { dg-do compile { target c++17 } } +// { dg-options "-O2 -w" } + +void foo (); +template <typename T> struct A : T { long bar () const; }; +int a; + +template <typename T> +long +A<T>::bar () const +{ + return this->baz ()[a]; +} + +struct B { + struct { long b[1]; long c; } u; + unsigned d; + int e; + B (const B &); + ~B (); + const long *baz () const; + unsigned qux () const; +}; + +B::B (const B &) +{ + if (__builtin_expect (e, 0)) + u.c = 0; +} + +B::~B () +{ + if (__builtin_expect (e, 0)) + foo (); +} + +const long * +B::baz () const +{ + return u.b; +} + +unsigned +B::qux () const +{ + return d; +} + +struct C { A<B> corge () const; A<B> *f; }; + +A<B> +C::corge () const +{ + return f[1]; +} + +void +test (C r, long *h, unsigned short *d) +{ + for (int j = 0; j < 8; ++j) + { + A g = r.corge (); + *d = g.qux (); + for (unsigned i = 0; i < *d; ++i) + *h++ = g.bar (); + } +}