From patchwork Wed Sep 11 07:52:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1160719 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-508818-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Gu7y2ymx"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46SvJc2Dz8z9sCJ for ; Wed, 11 Sep 2019 17:52:45 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=Sf41OgOZ55k+994hIPnPhORRoiEzu 2kmSpbGaPpiMsWMFY2SE6KVzYlA6Osr0FKw7rwaq5MAz2jGhzNaf7Auow5XLiCku vas/vHvBzzK/SXjbHQtm62iNEx66KArmV86VO+0gOjp50fB7xypBGF7nvdJYxpPX lO7/hg87Te7B5s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=a+zhspUlEfRLjKCC3o74FZCRbY8=; b=Gu7 y2ymxCo1wv5COvGMbNoObQHT4Kwgc+c4Whuyzq7HZiN+cQDDXCYzPW8xqOX4P4II Ul7Xl7mYuVuK4mwtJNBmnCq9b70oJAEwe7aH+lOZJiG9YS3pCAlfMhMmZJZZNv7o oAWXmKC13nYBv0YFqdDkoK1/py7e1BQoU/RGtgvM= Received: (qmail 53748 invoked by alias); 11 Sep 2019 07:52:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 53736 invoked by uid 89); 11 Sep 2019 07:52:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Sep 2019 07:52:36 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0833A18CB8F1; Wed, 11 Sep 2019 07:52:35 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-139.ams2.redhat.com [10.36.116.139]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8DF0460BEC; Wed, 11 Sep 2019 07:52:34 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x8B7qW8E026727; Wed, 11 Sep 2019 09:52:32 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x8B7qVxw026726; Wed, 11 Sep 2019 09:52:31 +0200 Date: Wed, 11 Sep 2019 09:52:30 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up match.pd ICE on kernel build (PR middle-end/91725) Message-ID: <20190911075230.GE2120@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) X-IsSubscribed: yes Hi! My recent change broke Linux kernel build, where we ICE in get_nonzero_bits which apparently assumes it must be called only on INTEGER_CSTs or SSA_NAMEs, while during generic folding it can be called say with PLUS_EXPR etc. tree_nonzero_bits apparently can be called on any tree code, as it has the return -1 fallback, but it doesn't really handle vector types, because it uses TYPE_PRECISION instead of element_precision. get_nonzero_bits also doesn't do anything useful for vector types, INTEGER_CSTs aren't vectors and vector type SSA_NAMEs won't really have range info (though, uses element_precision). In theory for VECTOR_CSTs we could or in get_nonzero_bits from all elements together or something similar, but still for SSA_NAMEs as we don't track anything it won't be useful, so this patch just punts on vector types if there is a widening conversion from signed. After all, a widening conversion for vectors wouldn't be really a conversion, but VEC_UNPACK_{LO,HI}_EXPR. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-09-11 Jakub Jelinek PR middle-end/91725 * match.pd ((A / (1 << B)) -> (A >> B)): Call tree_nonzero_bits instead of get_nonzero_bits, only call it for integral types. * gcc.c-torture/compile/pr91725.c: New test. Jakub --- gcc/match.pd.jj 2019-09-10 10:13:29.723000308 +0200 +++ gcc/match.pd 2019-09-10 20:14:06.164054126 +0200 @@ -325,9 +325,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (TYPE_UNSIGNED (TREE_TYPE (@1)) || (element_precision (type) == element_precision (TREE_TYPE (@1))) - || (get_nonzero_bits (@0) - & wi::mask (element_precision (TREE_TYPE (@1)) - 1, true, - element_precision (type))) == 0)))) + || (INTEGRAL_TYPE_P (type) + && (tree_nonzero_bits (@0) + & wi::mask (element_precision (TREE_TYPE (@1)) - 1, + true, + element_precision (type))) == 0))))) (rshift @0 @2))) /* Preserve explicit divisions by 0: the C++ front-end wants to detect --- gcc/testsuite/gcc.c-torture/compile/pr91725.c.jj 2019-09-10 20:09:39.499987576 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr91725.c 2019-09-10 20:08:21.302141038 +0200 @@ -0,0 +1,7 @@ +/* PR middle-end/91725 */ + +unsigned long long +foo (unsigned long long x, unsigned long long y, int z) +{ + return (x + y) / (1 << z); +}