Message ID | ZZkWh7Sz1/ugsVjU@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 y1csp16303dyq; Sat, 6 Jan 2024 01:00:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeS1Q9xcwbnMsRD+vFCxuRpms02bNjIUlgsVz+zvcJrNAc0PULLcN7FuI9kM8JujS2vl48 X-Received: by 2002:a05:6214:1949:b0:680:d1e6:3f17 with SMTP id q9-20020a056214194900b00680d1e63f17mr626681qvk.65.1704531656173; Sat, 06 Jan 2024 01:00:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704531656; cv=pass; d=google.com; s=arc-20160816; b=BRKyKtu0VaDpQY0OkG3vTIclOBCXVY7OS8tAe2uuk0uJtE2ag/dUtEFCngsfg/ln5j xwLt0c3R30ehD2eXzw62oa0BEjMd2LZ8XJc/bGldO/i5vB0WivdaXsna+X98LoZQSzWj zyv2Eqd13Hu/75l+Rzn5pEkKbJXEp8gUi9zpRzHMQqSU9cqYu64eRoe7AMiGKJaLupGE lKst5Nb4DFlui8eR0jpE6e7H5KKg+Xc2X3Mgnx50FewYFXmI0zVbzMDydEGDh+F5f03F +cPW+aOOJRrbv+PGBiuwUg7BJWAx3AX89SeMerVkzNF8RmMwMGGhH9TPFGkd+jxYaBk2 MoDg== 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=usQgKSxoArYL4cbtkru5lz809FoBGvCRbG8RB2SoooY=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=seJsHKPWCm3u0cvK+iZGhYu7xcde+v7Rn+prNL/OcE4i8V8gySkMzQI1D4SFqT1Rth 9wZ136FGAmVrQRVsWXcvpbd0E/gVdeuSyrPU6RgJL8W9Ew98lQKHFeR7TON7AfiMNq4+ HZYdmCzjZdDWWWq6DCOF0oSPGfgMgo+m6NmMegevAEcHxikDG+oX9Yljb7doNga+K01u /2HCrlpRWkRs3SlzH6vfOiwcyPWexPYX9b91ZHiuwZOfpgjU9hL2c9kEXd6z2lwNhhIO kzCvPxyH253oZIJPlSTZpm574bpnA12/GAYDCeG8zpqbUZqTA/LoVcpsd3bV6Nc8Wzt4 95ag== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D2ul5hLB; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x18-20020a0cda12000000b0067fd61f5a8asi3592997qvj.301.2024.01.06.01.00.56 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 01:00:56 -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=D2ul5hLB; 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 DB5FC3858C98 for <ouuuleilei@gmail.com>; Sat, 6 Jan 2024 09:00:55 +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 CE4DC3858D3C for <gcc-patches@gcc.gnu.org>; Sat, 6 Jan 2024 09:00:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE4DC3858D3C 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 CE4DC3858D3C 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=1704531609; cv=none; b=nyqVvzvZzuEf98N2Oj60qMuqfefOcYTUZ2G1vczYvU/vyroPpqVSQVL86ZhuZEgY2xrfzouFuIr2G44cefFCR9d+21pN7DrukysbN7C7B6hRwowujOTooFg2k0mU8zisFtRHYHXAQk82/LhwkI087sQxTXFafsHudYQ/vu0u5Ng= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704531609; c=relaxed/simple; bh=7SWgz9vVPtf9B0jzijH3WbH871icHr87yueGboLvnjI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=ZtVpxg769ijhP4JsaKo/owiOHeVL//jFv3cQaBfDLwU6kvgl0TIGcYDh1AVkAgEQJaEj3ld665hRmTBbWRVW5AU5xWXUbQT2gzQLrQQiYtROh3tA6rZRDyVtMx/U/WtxycEhP5M0AZhtm+j9gjeZiZI4VqVND+G0h4PDT3Qzgzw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704531606; 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=usQgKSxoArYL4cbtkru5lz809FoBGvCRbG8RB2SoooY=; b=D2ul5hLBvigKWbYEoTSyYjF2H3ayHhcAvtptF/ZIQxrnQ2hkF7kPQfGuS9lNlC6wbD21wp Ao2VULRDa4gFLUThBgtCASP4ciwnTwEFo1m6rCYYhEyyH91NEj0azbqi6tKyP4rVMkqPH7 HhfBb4F20WnqgOk7zMvbm3xMt+AoGR8= 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-575-LplbauTSNvOOFgh8JPB4BA-1; Sat, 06 Jan 2024 03:59:55 -0500 X-MC-Unique: LplbauTSNvOOFgh8JPB4BA-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 4F0528352A0; Sat, 6 Jan 2024 08:59:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11A772166B33; Sat, 6 Jan 2024 08:59:54 +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 4068xqsW2724878 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 6 Jan 2024 09:59:52 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4068xptn2724876; Sat, 6 Jan 2024 09:59:51 +0100 Date: Sat, 6 Jan 2024 09:59:51 +0100 From: Jakub Jelinek <jakub@redhat.com> To: Richard Biener <rguenther@suse.de> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] vect: Fix ICE in vect_analyze_loop_costing [PR113210] Message-ID: <ZZkWh7Sz1/ugsVjU@tucnak> MIME-Version: 1.0 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=-4.7 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_H4, 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: 1787330985640610361 X-GMAIL-MSGID: 1787330985640610361 |
Series |
vect: Fix ICE in vect_analyze_loop_costing [PR113210]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Jan. 6, 2024, 8:59 a.m. UTC
Hi! The following testcase ICEs (on ARM/RISCV with certain options), because niters analysis computes number of latch executions for the loop as (short unsigned int) (a.0_1 + 255) + 1 > 256 ? ~(short unsigned int) (a.0_1 + 255) : 0 where a.0_1 is unsigned char. This is correct, but given that a.0_1 + 255 is done in unsigned char the condition is never true and so it is actually equivalent to 0, but the folders don't know that. The vectorizer sets LOOP_VINFO_NITERSM1 to that expression and does on with computing LOOP_VINFO_NITERS by fold_build2 PLUS_EXPR of that expression unshared and INTEGER_CST one. In that folding we trigger various optimizations, first it is correctly simplified into (short unsigned int) (a.0_1 + 255) + 1 > 256 ? -(short unsigned int) (a.0_1 + 255) : 1 and next using /* (X + 1) > Y ? -X : 1 simplifies to X >= Y ? -X : 1 when X is unsigned, as when X + 1 overflows, X is -1, so -X == 1. */ into (short unsigned int) (a.0_1 + 255) >= 256 ? -(short unsigned int) (a.0_1 + 255) : 1 and for this the first COND_EXPR argument is folded and figured out to be 0 and so while LOOP_VINFO_NITERSM1 is a complex expression (unknown to be equivalent to 0), LOOP_VINFO_NITERS is INTEGER_CST 1. vect_analyze_loop_costing then uses LOOP_VINFO_NITERS_KNOWN_P (which checks if LOOP_VINFO_NITERS is INTEGER_CST which fits into shwi or something like that) and from that assumes that LOOP_VINFO_NITERSM1 will be INTEGER_CST. The following patch fixes that by adding verification for that too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-06 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/113210 * tree-vect-loop.cc (vect_analyze_loop_costing): If LOOP_VINFO_NITERSM1 is not INTEGER_CST, don't try to use it. * gcc.c-torture/compile/pr113210.c: New test. Jakub
Comments
On 1/6/24 01:59, Jakub Jelinek wrote: > Hi! > > The following testcase ICEs (on ARM/RISCV with certain options), because niters analysis > computes number of latch executions for the loop as > (short unsigned int) (a.0_1 + 255) + 1 > 256 ? ~(short unsigned int) (a.0_1 + 255) : 0 > where a.0_1 is unsigned char. This is correct, but given that a.0_1 + 255 > is done in unsigned char the condition is never true and so it is actually > equivalent to 0, but the folders don't know that. > The vectorizer sets LOOP_VINFO_NITERSM1 to that expression and does on with > computing LOOP_VINFO_NITERS by fold_build2 PLUS_EXPR of that expression > unshared and INTEGER_CST one. In that folding we trigger various > optimizations, first it is correctly simplified into > (short unsigned int) (a.0_1 + 255) + 1 > 256 ? -(short unsigned int) (a.0_1 + 255) : 1 > and next using > /* (X + 1) > Y ? -X : 1 simplifies to X >= Y ? -X : 1 when > X is unsigned, as when X + 1 overflows, X is -1, so -X == 1. */ > into > (short unsigned int) (a.0_1 + 255) >= 256 ? -(short unsigned int) (a.0_1 + 255) : 1 > and for this the first COND_EXPR argument is folded and figured out to be 0 > and so while LOOP_VINFO_NITERSM1 is a complex expression (unknown to be > equivalent to 0), LOOP_VINFO_NITERS is INTEGER_CST 1. > vect_analyze_loop_costing then uses LOOP_VINFO_NITERS_KNOWN_P (which checks > if LOOP_VINFO_NITERS is INTEGER_CST which fits into shwi or something like > that) and from that assumes that LOOP_VINFO_NITERSM1 will be INTEGER_CST. > > The following patch fixes that by adding verification for that too. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2024-01-06 Jakub Jelinek <jakub@redhat.com> > > PR tree-optimization/113210 > * tree-vect-loop.cc (vect_analyze_loop_costing): If LOOP_VINFO_NITERSM1 > is not INTEGER_CST, don't try to use it. > > * gcc.c-torture/compile/pr113210.c: New test. OK jeff
--- gcc/tree-vect-loop.cc.jj 2024-01-03 11:51:22.787852547 +0100 +++ gcc/tree-vect-loop.cc 2024-01-05 17:12:06.511512557 +0100 @@ -2264,7 +2264,8 @@ vect_analyze_loop_costing (loop_vec_info epilogue we can also decide whether the main loop leaves us with enough iterations, prefering a smaller vector epilog then also possibly used for the case we skip the vector loop. */ - if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)) + if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) + && TREE_CODE (LOOP_VINFO_NITERSM1 (loop_vinfo)) == INTEGER_CST) { widest_int scalar_niters = wi::to_widest (LOOP_VINFO_NITERSM1 (loop_vinfo)) + 1; --- gcc/testsuite/gcc.c-torture/compile/pr113210.c.jj 2024-01-05 17:18:29.792257043 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr113210.c 2024-01-05 17:17:57.522699521 +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) + ; +}