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.133.124]) by sourceware.org (Postfix) with ESMTPS id A47A9385829F for ; Thu, 1 Sep 2022 11:19:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A47A9385829F 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=1662031142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kjvu89fcFlJ2/Mj8vkj1nTpFKrSuvmCzbuTnwj6Whsk=; b=b/1Vr8S2wdsCEEgexJKHYnc4n0ZYcOpW4b/SX8MRw3lQv7ZgI2F/8na4IYC79cAEs23Olr KsF5gEfJuC6KNMWxRZokZL9x/fAyoYrFnu1jT73DbpvrPZl/s6GslvjuInsilOOfaQ6BZ7 AchYEZV7qJFK/KeLOp5oGony1b34CKs= 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-452-xiE4CjLkNB2ZXECrfYM-ag-1; Thu, 01 Sep 2022 07:18:59 -0400 X-MC-Unique: xiE4CjLkNB2ZXECrfYM-ag-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1650101A54E; Thu, 1 Sep 2022 11:18:58 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6ACC3492C3B; Thu, 1 Sep 2022 11:18:58 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 281BIup42596639 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 1 Sep 2022 13:18:56 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 281BIuFP2596638; Thu, 1 Sep 2022 13:18:56 +0200 From: Aldy Hernandez To: GCC patches Cc: Jakub Jelinek , Andrew MacLeod , Jeff Law , Aldy Hernandez Subject: [COMMITTED] Implement ranger folder for __builtin_signbit. Date: Thu, 1 Sep 2022 13:18:51 +0200 Message-Id: <20220901111851.2595874-2-aldyh@redhat.com> In-Reply-To: <20220901111851.2595874-1-aldyh@redhat.com> References: <20220901111851.2595874-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: Now that we keep track of the signbit, we can use it to fold __builtin_signbit. I am assuming I don't have try too hard to get the actual signbit number and 1 will do. Especially, since we're inconsistent in trunk whether we fold the builtin or whether we calculate it at runtime. abulafia:~$ cat a.c float nzero = -0.0; main(){ printf("0x%x\n", __builtin_signbit(-0.0)); printf("0x%x\n", __builtin_signbit(nzero)); } abulafia:~$ gcc a.c -w && ./a.out 0x1 0x80000000 It is amazing that we've been failing to fold something as simple as this: if (x > 5.0) num = __builtin_signbit (x); It does the right thing now :-P. gcc/ChangeLog: * gimple-range-fold.cc (fold_using_range::range_of_builtin_int_call): Add case for CFN_BUILT_IN_SIGNBIT. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/vrp-float-signbit-1.c: New test. --- gcc/gimple-range-fold.cc | 20 +++++++++++++++++++ .../gcc.dg/tree-ssa/vrp-float-signbit-1.c | 12 +++++++++++ 2 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-1.c diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index b0b22106320..d8497fc9be7 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -1023,6 +1023,26 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, break; } + case CFN_BUILT_IN_SIGNBIT: + { + arg = gimple_call_arg (call, 0); + frange tmp; + if (src.get_operand (tmp, arg)) + { + if (tmp.get_signbit ().varying_p ()) + return false; + if (tmp.get_signbit ().yes_p ()) + { + tree one = build_one_cst (type); + r.set (one, one); + } + else + r.set_zero (type); + return true; + } + break; + } + case CFN_BUILT_IN_TOUPPER: { arg = gimple_call_arg (call, 0); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-1.c new file mode 100644 index 00000000000..3fa783ec460 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-1.c @@ -0,0 +1,12 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-evrp" } + +int num; + +void func(float x) +{ + if (x > 5.0) + num = __builtin_signbit (x); +} + +// { dg-final { scan-tree-dump-times "num = 0;" 1 "evrp" } } -- 2.37.1