vect: Ensure both NITERSM1 and NITERS are INTEGER_CSTs or neither of them [PR113210]
Message ID | ZZ0HuOnrY+ZxfYQu@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp1520640dyq; Tue, 9 Jan 2024 00:49:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNNlMfLtuBfdlv8cnxMDmj8bc6JYmRAX3iq/u9ao9u7TonZsBum8MmRJurY4GILuVAAS+L X-Received: by 2002:ad4:5368:0:b0:680:f96f:84c0 with SMTP id e8-20020ad45368000000b00680f96f84c0mr5381040qvv.15.1704790173500; Tue, 09 Jan 2024 00:49:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704790173; cv=pass; d=google.com; s=arc-20160816; b=yEu3B1COH0p/jeDuUP+ovdob1bTd+4eNUyIs3d3r8Kwl7ReP2BRFXWlzB9sJic8NKW EK5AC4wkmWwqa4BBuHG9N2Z06HqnvJN/Ttp/fIUXhEUXCCxpcPgYUzkMzNDf2btctbJX 6OazlV5d87eQxhdY63+Bc21YxWW5YL1POkcRZYgIPT8Pj9uTgmR0C5TZ3GpxQY7XbQF8 xX/0d9yXKfKV0H7nf4/NoXmEbdH4O5/a1ydcD1qOr1yADlXMNfEpqTjL1xVaS9R56yy5 RRBKsNOaT5kD4UT94EcJ74z0x9pMyoyP9eYsySqMXL5Vrl9gdG3Vef4tKOSx9GJnaxwJ KKNQ== 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 :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=SJfYeS73RuHm+IT+15aHxaaVUK9W1vNFfR+AC6HmpeI=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=kwsaEVs7wUX06LsR1e5QbpDNyij1uSQd+du+HS4Ti8xNvUFBdeI97WBLKUVZc7Laiy L5dxzjUxAyBxjnU1aW2QRTunnzB2lgiSA85HlFv+4vgh3bih1eNnsEuJXg5SARVdG6ps Rjpr8m8WUXNk7sWxL+ENnKdN8Arme5yX1iU+1ToPTaoiqVJGsopm86/41b+moosZm+ka wI5ALfH+JU0s74Je/gh+JDkuGDjs/Lo0GUW5vTx15fo6P8sgK/3zePGfYt2QmsXCgBO9 uKwC1fsoYOmX2VzPqQ78Ab0Osx3+VniwjPtjFBOVjl8G1AjiJ9mcOP1cBJt+7hzsIWKs kOKQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LJ888eFO; 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k20-20020a0cb254000000b0067f3bfc3e80si1830138qve.321.2024.01.09.00.49.33 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 00:49:33 -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=@redhat.com header.s=mimecast20190719 header.b=LJ888eFO; 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A41D7385803A for <ouuuleilei@gmail.com>; Tue, 9 Jan 2024 08:49:32 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 3E9BB38582B4 for <gcc-patches@gcc.gnu.org>; Tue, 9 Jan 2024 08:45:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E9BB38582B4 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 3E9BB38582B4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704789956; cv=none; b=vI9MXTxfcoavnKBgiGojaKMpwcJTve/KUsboe+s+K/cuyR5XdXFMmABQw/WYhS7WHXGVuVkJKxVN0f6htNVAI2y2goGFzQrqwvcUSzUEH8RIyYrOPlcqP0Sw5Swh2spXtMrBD3RXewIveYj7FwJcAgV9jJfy3gNYGcp+nbn65b0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704789956; c=relaxed/simple; bh=0FqLNN7UyZzC22BNwntEAu3mBaOZKneeF40oYm5jTr0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=BuIWbdCaFobqftL7hFGqXbhW1+tZdXcBzAzRA9/wn1C2tYUCn988jQpQePW0W12RdIBOg2wyJsdFiEKCqKZWv4YRiFWt5VQ3Um24Req0Nca7WsUJxRjQmGgGmlJECXmB+DhVIKHlzBa2unEUpYtBaHj5J48rJH4AQblUmiDVeBU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704789949; 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; bh=SJfYeS73RuHm+IT+15aHxaaVUK9W1vNFfR+AC6HmpeI=; b=LJ888eFOWikN0X/k8VleMrsZBaQAxTOhV/SSwpYYbBB4JSFKe8CT/O5cMkDjTzp9LunzV4 yccsl/Be6b6B0GTAqwjb7OXDqTFWI8TRgz1c1/TOmEYaNI/rxAwKkI/RkA2G7HCW+TXuKm RJQkIq1f1wlrHnL3+Y2UEMF42hkVVkk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-OsR2OIMKPdqXxOqMV-FAIQ-1; Tue, 09 Jan 2024 03:45:48 -0500 X-MC-Unique: OsR2OIMKPdqXxOqMV-FAIQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 579AA185A782; Tue, 9 Jan 2024 08:45:48 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B9361C060AF; Tue, 9 Jan 2024 08:45:47 +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 4098jjQM1771433 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 09:45:45 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4098jiNL1771432; Tue, 9 Jan 2024 09:45:44 +0100 Date: Tue, 9 Jan 2024 09:45:44 +0100 From: Jakub Jelinek <jakub@redhat.com> To: Richard Biener <rguenther@suse.de> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] vect: Ensure both NITERSM1 and NITERS are INTEGER_CSTs or neither of them [PR113210] Message-ID: <ZZ0HuOnrY+ZxfYQu@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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=-4.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 <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: 1787602060924230316 X-GMAIL-MSGID: 1787602060924230316 |
Series |
vect: Ensure both NITERSM1 and NITERS are INTEGER_CSTs or neither of them [PR113210]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Jan. 9, 2024, 8:45 a.m. UTC
Hi! On the following testcase e.g. on riscv64 or aarch64 (latter with -O3 -march=armv8-a+sve ) we ICE, because while NITERS is INTEGER_CST, NITERSM1 is a complex expression like (short unsigned int) (a.0_1 + 255) + 1 > 256 ? ~(short unsigned int) (a.0_1 + 255) : 0 where a.0_1 is unsigned char. The condition is never true, so the above is equivalent to just 0, but only when trying to fold the above with PLUS_EXPR 1 we manage to simplify it (first ~(short unsigned int) (a.0_1 + 255) to -(short unsigned int) (a.0_1 + 255) and then (short unsigned int) (a.0_1 + 255) + 1 > 256 ? -(short unsigned int) (a.0_1 + 255) : 1 to (short unsigned int) (a.0_1 + 255) >= 256 ? -(short unsigned int) (a.0_1 + 255) : 1 and only at this point we fold the condition to be false. But the vectorizer seems to assume that if NITERS is known (i.e. suitable INTEGER_CST) then NITERSM1 also is, so the following hack ensures that if NITERS folds into INTEGER_CST NITERSM1 will be one as well. Bootstrapped/regtested on x86_64-linux and i686-linux, additionally tested with cross to aarch64-linux with that -O3 -march=armv8-a+sve on the testcase, ok for trunk? 2024-01-09 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/113210 * tree-vect-loop.cc (vect_get_loop_niters): If non-INTEGER_CST value in *number_of_iterationsm1 PLUS_EXPR 1 is folded into INTEGER_CST, recompute *number_of_iterationsm1 as the INTEGER_CST minus 1. * gcc.c-torture/compile/pr113210.c: New test. Jakub
Comments
On Tue, 9 Jan 2024, Jakub Jelinek wrote: > Hi! > > On the following testcase e.g. on riscv64 or aarch64 (latter with > -O3 -march=armv8-a+sve ) we ICE, because while NITERS is INTEGER_CST, > NITERSM1 is a complex expression like > (short unsigned int) (a.0_1 + 255) + 1 > 256 ? ~(short unsigned int) (a.0_1 + 255) : 0 > where a.0_1 is unsigned char. The condition is never true, so the above > is equivalent to just 0, but only when trying to fold the above with > PLUS_EXPR 1 we manage to simplify it (first > ~(short unsigned int) (a.0_1 + 255) > to > -(short unsigned int) (a.0_1 + 255) > and then > (short unsigned int) (a.0_1 + 255) + 1 > 256 ? -(short unsigned int) (a.0_1 + 255) : 1 > to > (short unsigned int) (a.0_1 + 255) >= 256 ? -(short unsigned int) (a.0_1 + 255) : 1 > and only at this point we fold the condition to be false. > > But the vectorizer seems to assume that if NITERS is known (i.e. suitable > INTEGER_CST) then NITERSM1 also is, so the following hack ensures that if > NITERS folds into INTEGER_CST NITERSM1 will be one as well. > > Bootstrapped/regtested on x86_64-linux and i686-linux, additionally tested > with cross to aarch64-linux with that -O3 -march=armv8-a+sve on the > testcase, ok for trunk? OK. > 2024-01-09 Jakub Jelinek <jakub@redhat.com> > > PR tree-optimization/113210 > * tree-vect-loop.cc (vect_get_loop_niters): If non-INTEGER_CST > value in *number_of_iterationsm1 PLUS_EXPR 1 is folded into > INTEGER_CST, recompute *number_of_iterationsm1 as the INTEGER_CST > minus 1. > > * gcc.c-torture/compile/pr113210.c: New test. > > --- gcc/tree-vect-loop.cc.jj 2024-01-08 16:13:18.682939712 +0100 > +++ gcc/tree-vect-loop.cc 2024-01-08 16:30:24.062626368 +0100 > @@ -941,9 +941,22 @@ vect_get_loop_niters (class loop *loop, > ??? For UINT_MAX latch executions this number overflows to zero > for loops like do { n++; } while (n != 0); */ > if (niter && !chrec_contains_undetermined (niter)) > + { > niter = fold_build2 (PLUS_EXPR, TREE_TYPE (niter), > unshare_expr (niter), > build_int_cst (TREE_TYPE (niter), 1)); > + if (TREE_CODE (niter) == INTEGER_CST > + && TREE_CODE (*number_of_iterationsm1) != INTEGER_CST) > + { > + /* If we manage to fold niter + 1 into INTEGER_CST even when > + niter is some complex expression, ensure back > + *number_of_iterationsm1 is an INTEGER_CST as well. See > + PR113210. */ > + *number_of_iterationsm1 > + = fold_build2 (PLUS_EXPR, TREE_TYPE (niter), niter, > + build_minus_one_cst (TREE_TYPE (niter))); > + } > + } > *number_of_iterations = niter; > } > > --- gcc/testsuite/gcc.c-torture/compile/pr113210.c.jj 2024-01-08 16:17:16.672620793 +0100 > +++ gcc/testsuite/gcc.c-torture/compile/pr113210.c 2024-01-08 16:17:16.671620807 +0100 > @@ -0,0 +1,13 @@ > +/* PR tree-optimization/113210 */ > + > +unsigned char a, c; > +unsigned short b; > + > +void > +foo (void) > +{ > + c = a + 255; > + b = c; > + while (++b > 256) > + ; > +} > > Jakub > >
--- gcc/tree-vect-loop.cc.jj 2024-01-08 16:13:18.682939712 +0100 +++ gcc/tree-vect-loop.cc 2024-01-08 16:30:24.062626368 +0100 @@ -941,9 +941,22 @@ vect_get_loop_niters (class loop *loop, ??? For UINT_MAX latch executions this number overflows to zero for loops like do { n++; } while (n != 0); */ if (niter && !chrec_contains_undetermined (niter)) + { niter = fold_build2 (PLUS_EXPR, TREE_TYPE (niter), unshare_expr (niter), build_int_cst (TREE_TYPE (niter), 1)); + if (TREE_CODE (niter) == INTEGER_CST + && TREE_CODE (*number_of_iterationsm1) != INTEGER_CST) + { + /* If we manage to fold niter + 1 into INTEGER_CST even when + niter is some complex expression, ensure back + *number_of_iterationsm1 is an INTEGER_CST as well. See + PR113210. */ + *number_of_iterationsm1 + = fold_build2 (PLUS_EXPR, TREE_TYPE (niter), niter, + build_minus_one_cst (TREE_TYPE (niter))); + } + } *number_of_iterations = niter; } --- gcc/testsuite/gcc.c-torture/compile/pr113210.c.jj 2024-01-08 16:17:16.672620793 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr113210.c 2024-01-08 16:17:16.671620807 +0100 @@ -0,0 +1,13 @@ +/* PR tree-optimization/113210 */ + +unsigned char a, c; +unsigned short b; + +void +foo (void) +{ + c = a + 255; + b = c; + while (++b > 256) + ; +}