From patchwork Tue Mar 14 08:01:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 69351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1623118wrd; Tue, 14 Mar 2023 01:02:05 -0700 (PDT) X-Google-Smtp-Source: AK7set/MKtmqcgY3SkakCphNCFoND84wooJxw1sX8APZlMfSRRL+NuYm6KPaj/Y5DxJEAl1DVMJw X-Received: by 2002:a05:6402:120f:b0:4fa:b302:84d0 with SMTP id c15-20020a056402120f00b004fab30284d0mr10208334edw.15.1678780925262; Tue, 14 Mar 2023 01:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678780925; cv=none; d=google.com; s=arc-20160816; b=pxqFpBk3qUyIBiJvnvGZXMbbylPgpoJFldjS46bQmosiQToIjx4QJ03KMIa+FVpBzm XPbcwKxvoYqkdBvAGhT0HiEIgFVgh951OWUtNyLCFfV7diSwYRr0WOLLR0XJq4Tz+SIK tf91ngRRMnDvkQvYCj+P/VYQMc/vF8g9lyL/DRmnCtqpcs2ByM0PDZnFhEX1Jr1JIKJ1 hPgPzTRNtS6dE/pPLN78Mpbh1kAghy87KyKAMbSLtGQiQP6RPQ0GG9oUZ55clwxzn7W8 2IbqAxAl2+N1BvAQBcBi6OTB0mSCfm9me+KhBLFjDrx7LyupMm8RafKFOpG6nT2VLa+y 6Tpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=1sKs5LtRdKAQtk1M3YrQCrXTbLmSoY06hhAd5VNUmzg=; b=aXC/uDWpOV8KDcuJrSb3FPyxTac6kw2JbgD6tbthuqWE8DliLacidzPtXxbLElYOKu D6ByTFI0AYnnOAoOI45K/YAXpZ7vjCfU1mAT5YwIdReq9GepyLRvlmGjPMG88KXOUM+p rl3ahD0LtOCjLElKdCaJ7kfqTRzMwULRwvOq5MIfGDxty+i7olMOb0pZYbKnsrvfPK9Q wncUwOKG3IKkmphpr0N+7CNI6j5DPdNsJXoTP6bPY5vn+PGSnyVJIf4LWPhO/5UgvOPm S2cfTZcJlNtbhYP3qnanO/PP9Vu9DajzbQP2rhVCFDSKX6cb7ZXiCbshgyheeb/LSPnl nxDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=q2FAvkTB; 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=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r13-20020aa7d58d000000b004aaa505ac5fsi2112784edq.76.2023.03.14.01.02.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 01:02:05 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=q2FAvkTB; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45F983858430 for ; Tue, 14 Mar 2023 08:02:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45F983858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678780924; bh=1sKs5LtRdKAQtk1M3YrQCrXTbLmSoY06hhAd5VNUmzg=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=q2FAvkTBFaJ8qGfmD/eF9ILVXpZxECPofm/Zf47evkMsuqvkv+7XfZhvAsTnhHCfC YSX7qRqES5x074zzdYNN5qTKKzOayVxFM8k9oY8uULdAY6BlsEJvxj7xpttw7BjT5Z Yy3ziXUUMp/vvZ2ytrUhIX3y2oyJ3nrlGJ9hszvs= 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 0B4493858D32 for ; Tue, 14 Mar 2023 08:01:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B4493858D32 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-351-7gcZCttGPcin8So6Y5BrVw-1; Tue, 14 Mar 2023 04:01:12 -0400 X-MC-Unique: 7gcZCttGPcin8So6Y5BrVw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA8D18027FD; Tue, 14 Mar 2023 08:01:11 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A925E492B00; Tue, 14 Mar 2023 08:01:11 +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 32E819oJ607025 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 14 Mar 2023 09:01:09 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32E818jK607024; Tue, 14 Mar 2023 09:01:08 +0100 Date: Tue, 14 Mar 2023 09:01:08 +0100 To: Richard Biener , Andrew MacLeod , Aldy Hernandez Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-vect-patterns: Fix up ICE in upper_bound [PR109115] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760329387270863337?= X-GMAIL-MSGID: =?utf-8?q?1760329387270863337?= Hi! As mentioned in the PR, range_of_expr returns false if the type of the expression isn't suitable for corresponding range type, but doesn't if the range is undefined for other reasons. Still, lower/upper_bound is defined only for ranges which actually have at least one pair of subranges, VR_UNDEFINED range doesn't have it. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-14 Jakub Jelinek PR tree-optimization/109115 * tree-vect-patterns.cc (vect_recog_divmod_pattern): Don't use r.upper_bound () on r.undefined_p () range. * gcc.dg/pr109115.c: New test. Jakub --- gcc/tree-vect-patterns.cc.jj 2023-03-12 22:36:06.388177607 +0100 +++ gcc/tree-vect-patterns.cc 2023-03-13 22:49:18.278476093 +0100 @@ -3973,7 +3973,7 @@ vect_recog_divmod_pattern (vec_info *vin /* Check that no overflow will occur. If we don't have range information we can't perform the optimization. */ - if (ranger.range_of_expr (r, oprnd0, stmt)) + if (ranger.range_of_expr (r, oprnd0, stmt) && !r.undefined_p ()) { wide_int max = r.upper_bound (); wide_int one = wi::shwi (1, prec); --- gcc/testsuite/gcc.dg/pr109115.c.jj 2023-03-13 22:56:27.269428198 +0100 +++ gcc/testsuite/gcc.dg/pr109115.c 2023-03-13 22:56:04.174753778 +0100 @@ -0,0 +1,20 @@ +/* PR tree-optimization/109115 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int a, b; + +int +main () +{ + unsigned short c = a, e = -1; + if (b) + { + unsigned d = (a ^ 1U) / a & c; + int f = (~d >> ~a) / e; + if (a) + f = a; + a = f; + } + return 0; +}