From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678780875; 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=1sKs5LtRdKAQtk1M3YrQCrXTbLmSoY06hhAd5VNUmzg=; b=Nka01kuO+OQOnj6fnfWsPpDIn9jbp1/IoHurtXz4Cpmu20HEmMjk4+O+ihwX6wydn6iMKB o0km9EIHyhtvxPbVOoeWBD1iVAhuMFOPLCpn+4oo38awgyvbP8b8eJ0lMrtruhI4W6gM8V YNZbz6NjTyneez0x3hqKJKqTx7V1lWU= 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 From: Jakub Jelinek 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: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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; +} Jakub