From patchwork Mon Sep 2 07:34:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1979548 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Cg7PXqfv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wy0rf6r32z1yXY for ; Mon, 2 Sep 2024 17:34:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11BBB385EC22 for ; Mon, 2 Sep 2024 07:34:40 +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 ESMTP id 44EBF3858C48 for ; Mon, 2 Sep 2024 07:34:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44EBF3858C48 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 44EBF3858C48 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=1725262459; cv=none; b=saHc1pudkeN+V9AtgZhMCDReitZZr+0/tOb8xt8Sr8yJiRM/TdU7FIpvHJntq0Xc96fJsQq5lnc9fg0KEH60+eJBkGFWP1UMH4Mz0HiaEh9r/99++UalBhcs9CBp5S0LKlVLGyCF2aRO7hdsYMkSfdCga/uEVUhX3fu5Fzo/z+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725262459; c=relaxed/simple; bh=O2QNNzNx6gjSxgK/emW5WWUJbDqNCOpKvQ5wCs/ED5o=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=bwJZ6yzEnFOvDnlWi6vNBU01fbC/e79uEa09mHBwB3OqItUZExy4pjBc90lzXQOeYX9/xYzk74nICQk57Xi11CS746jXKK+/cX+a4ZFCY6jnYnQyXwfUPjGZGISUF4qo/MQ2iF7zjcu3NQiC68NJA4w/d6BAmt03pXXOqVQpc1o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725262458; 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=sPn1FR9ixcEubYhD8KcirE9aINJF/dF6mK1Q+oCsGoM=; b=Cg7PXqfvNwQN8kuocwLPkfKjL+K1rbPVPPzAlLhDtJ5QUE+wwm307wKlwCCwD7zlSahHfO 7yd5l0NNDMbkLGRRG72ukuDyMGohp15sS3ujRNfVQb7KERcPDLAd3hQBqk1udUFKITq7E+ GnSM/SvRJTUFwhISFDEi5H2oMArKIj8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-365-o6DOV_jLOzajJhSllh0M3g-1; Mon, 02 Sep 2024 03:34:16 -0400 X-MC-Unique: o6DOV_jLOzajJhSllh0M3g-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6A6EE1955BED; Mon, 2 Sep 2024 07:34:13 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.29]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6271419560A3; Mon, 2 Sep 2024 07:34:12 +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 4827Y9203235814 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 2 Sep 2024 09:34:09 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4827Y9cD3235813; Mon, 2 Sep 2024 09:34:09 +0200 Date: Mon, 2 Sep 2024 09:34:08 +0200 From: Jakub Jelinek To: Richard Biener , Aldy Hernandez , Andrew MacLeod Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] ranger: Fix up range computation for CLZ [PR116486] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 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_H3, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The initial CLZ gimple-range-op.cc implementation handled just the case where second argument to .CLZ is equal to prec, but in r15-1014 I've added also handling of the -1 case. As the following testcase shows, incorrectly though for the case where the first argument has [0,0] range. If the second argument is prec, then the result should be [prec,prec] and that was handled correctly, but when the second argument is -1, the result should be [-1,-1] but instead it was incorrectly computed as [prec-1,prec-1] (when second argument is prec, mini is 0 and maxi is prec, while when second argument is -1, mini is -1 and maxi is prec-1). Fixed thusly (the actual handling is then similar to the CTZ [0,0] case), bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-09-02 Jakub Jelinek PR middle-end/116486 * gimple-range-op.cc (cfn_clz::fold_range): If lh is [0,0] and mini is -1, return [-1,-1] range rather than [prec-1,prec-1]. * gcc.dg/bitint-109.c: New test. Jakub --- gcc/gimple-range-op.cc.jj 2024-08-15 10:18:48.000000000 +0200 +++ gcc/gimple-range-op.cc 2024-08-31 18:23:14.547269372 +0200 @@ -972,8 +972,10 @@ cfn_clz::fold_range (irange &r, tree typ { // If CLZ_DEFINED_VALUE_AT_ZERO is 2 with VALUE of prec, // return [prec, prec] or [-1, -1], otherwise ignore the range. - if (maxi == prec || mini == -1) - mini = maxi; + if (maxi == prec) + mini = prec; + else if (mini == -1) + maxi = -1; } else if (mini >= 0) mini = newmini; --- gcc/testsuite/gcc.dg/bitint-109.c.jj 2024-08-31 18:25:15.111715665 +0200 +++ gcc/testsuite/gcc.dg/bitint-109.c 2024-08-31 18:26:02.015118452 +0200 @@ -0,0 +1,25 @@ +/* PR middle-end/116486 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-O2 -fno-tree-ccp" } */ + +unsigned u; + +#if __BITINT_MAXWIDTH__ >= 129 +#define N 0x100000000000000000000000000000000uwb +#else +#define N 0xffffffffffffffffuwb +#endif + +int +foo (void) +{ + return __builtin_stdc_first_leading_one (u / N); +} + +int +main () +{ + int x = foo (); + if (x) + __builtin_abort (); +}