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: 66358 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D013D3858D32 for ; Tue, 14 Mar 2023 08:01:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D013D3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678780908; bh=1sKs5LtRdKAQtk1M3YrQCrXTbLmSoY06hhAd5VNUmzg=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=yy/Akz0I8MOWUVlNPu98B5I9WBghJOpnxhtkZfzmL8ctRawWcLUQov2Z+ramdNgN1 PqrsYDP4Cys/TlJ8hGKwp3ZgUOCEUCCcEJijOjC01lcVFPnwfXWsJiMKm7dO0KHEtp 6Q0tKSqgiBlktlQik1bTt3ck6MPQDtlSZOE4Eks0= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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; +}