From patchwork Fri Dec 23 15:25:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 36290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp377780wrn; Fri, 23 Dec 2022 07:26:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXudcg+zCo4djfLTbUsy2etl2ZvnzruTjZSxfUgZRMi+HKJMJUTcQeOTA6Z21oJmUJts9BpM X-Received: by 2002:a17:906:dfe9:b0:7ad:c691:4a7d with SMTP id lc9-20020a170906dfe900b007adc6914a7dmr11923850ejc.52.1671809201765; Fri, 23 Dec 2022 07:26:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671809201; cv=none; d=google.com; s=arc-20160816; b=y14Tm4vOBKLyFHpnQT5c9XUrkAZF+9DDwAmzfoRCeYAQf3gWlmaM42XhZOY+24XJkf U+xA6sWSSzAg6lJ0u3TEL0JVLGX5KEaWmwab1oSKJAV6sgjXB2VlYocDb9brHXwMAYUI //k4joy0RvvetktvP09tklBNUOHvEbZE1JN5xHcIbXytj/nC5CQE/fuEqjFvSSttX24T ci8EVUvsoksGtWj032+CtiBgbGACFTLSR82NH5PfIskUJ5hyK6tDcTKJsdTNNNbuoHit 8tACUL/nVa3KQ/3MCXBJ2CedgOw1rxDIX4nHeFCzKgYWokV+Ue5t8kaBz0bWeRihJulS bhnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+cXjyfPCMNyWWOrFa2nkStyqvp9MbK+HKi3D34m5kKw=; b=u7yIRtqo0l/YZhUOfCZpHQegQuf/rtsYWzQXnRCLEtgeDlyyuaQmDQ09/V0z0poAqA iLI5KoRh8ZfgiQOQsGCyWxeTiP2D7WFQhsBiErdvYxWIre0OgeMlPtrNWpocAFd83nm7 eevKpLBQQ5ehiAELXggcdDRNVWtSWMjVYZ28ye+hz92YSS3DINTYzVh+Zn5uDEYaVsZW NJilYQIjfw6SBsTDuSqpc/N/cHbtiYbK6t6YQLt+RzENwI27ICFc6ecGV175DUM/eZyf 4KAUGYvywEIPZTHcymOwrnbOMXDHTDFIB2v67Fdl39mADpRUI2t2sDjDij+YOnwo4iRV 5lAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YzXG2h9Q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cs18-20020a170906dc9200b007aedb84056csi3052802ejc.718.2022.12.23.07.26.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Dec 2022 07:26:41 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YzXG2h9Q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A4B63850F07 for ; Fri, 23 Dec 2022 15:26:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A4B63850F07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671809196; bh=+cXjyfPCMNyWWOrFa2nkStyqvp9MbK+HKi3D34m5kKw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YzXG2h9QfAiX7R5Nx3WalzIXtAcJ1SYrkB0TnFaMs1McpZXHt5KNNQXFEfMDfmUx/ kQIaRGYTZYpoaRCiRn+FKpUHlosDkIS2E5LuGC6tL2nsKxt/77RAwD0Qu9WMt60hRV PxlIuMcSf28XOHzeEB2lZzK+2av4od616cCd3G70= 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 3727C38555A2 for ; Fri, 23 Dec 2022 15:25:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3727C38555A2 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-177-B4m0vQmgPwmBrKGHsI9Ozg-1; Fri, 23 Dec 2022 10:25:46 -0500 X-MC-Unique: B4m0vQmgPwmBrKGHsI9Ozg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DDABD1C0754E for ; Fri, 23 Dec 2022 15:25:45 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C8942026D4B for ; Fri, 23 Dec 2022 15:25:44 +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 2BNFPQR33297312 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Fri, 23 Dec 2022 16:25:27 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BNFPQpN3297311 for gcc-patches@gcc.gnu.org; Fri, 23 Dec 2022 16:25:26 +0100 Date: Fri, 23 Dec 2022 16:25:26 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] tree-ssa-dom: can_infer_simple_equiv fixes [PR108068] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753019005747043783?= X-GMAIL-MSGID: =?utf-8?q?1753019005747043783?= Hi! As reported in the PR, tree-ssa-dom.cc uses real_zerop call to find if a floating point constant is zero and it shouldn't try to infer equivalences from comparison against it if signed zeros are honored. This doesn't work at all for decimal types, because real_zerop always returns false for them (one can have different representations of decimal zero beyond -0/+0), and it doesn't work for vector compares either, as real_zerop checks if all elements are zero, while we need to avoid infering equivalences from comparison against vector constants which have at least one zero element in it (if signed zeros are honored). Furthermore, as mentioned by Joseph, for decimal types many other values aren't singleton. So, this patch stops infering anything if element mode is decimal, and otherwise uses instead of real_zerop a new function, real_maybe_zerop, which will work even for decimal types and for complex or vector will return true if any element is or might be zero (so it returns true for anything but constants for now). Bootstrapped/regtested on x86_64-linux and i686-linux, acked by Richi in the PR, committed to trunk. 2022-12-23 Jakub Jelinek PR tree-optimization/108068 * tree.h (real_maybe_zerop): Declare. * tree.cc (real_maybe_zerop): Define. * tree-ssa-dom.cc (record_edge_info): Use it instead of real_zerop or TREE_CODE (op1) == SSA_NAME || real_zerop. Always set can_infer_simple_equiv to false for decimal floating point types. * gcc.dg/dfp/pr108068.c: New test. Jakub --- gcc/tree.h.jj 2022-12-21 09:03:45.722562726 +0100 +++ gcc/tree.h 2022-12-21 16:34:56.316622678 +0100 @@ -5497,6 +5497,7 @@ extern bool needs_to_live_in_memory (con extern tree reconstruct_complex_type (tree, tree); extern bool real_onep (const_tree); extern bool real_minus_onep (const_tree); +extern bool real_maybe_zerop (const_tree); extern void init_ttree (void); extern void build_common_tree_nodes (bool); extern void build_common_builtin_nodes (void); --- gcc/tree.cc.jj 2022-12-21 09:03:45.719562769 +0100 +++ gcc/tree.cc 2022-12-21 16:35:46.567899636 +0100 @@ -3180,6 +3180,35 @@ real_minus_onep (const_tree expr) } } +/* Return true if T could be a floating point zero. */ + +bool +real_maybe_zerop (const_tree expr) +{ + switch (TREE_CODE (expr)) + { + case REAL_CST: + /* Can't use real_zerop here, as it always returns false for decimal + floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero + either, as decimal zeros are rvc_normal. */ + return real_equal (&TREE_REAL_CST (expr), &dconst0); + case COMPLEX_CST: + return (real_maybe_zerop (TREE_REALPART (expr)) + || real_maybe_zerop (TREE_IMAGPART (expr))); + case VECTOR_CST: + { + unsigned count = vector_cst_encoded_nelts (expr); + for (unsigned int i = 0; i < count; ++i) + if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i))) + return true; + return false; + } + default: + /* Perhaps for SSA_NAMEs we could query frange. */ + return true; + } +} + /* Nonzero if EXP is a constant or a cast of a constant. */ bool --- gcc/tree-ssa-dom.cc.jj 2022-11-23 09:24:48.781253319 +0100 +++ gcc/tree-ssa-dom.cc 2022-12-21 16:36:37.756163125 +0100 @@ -615,9 +615,9 @@ record_edge_info (basic_block bb) { tree cond = build2 (code, boolean_type_node, op0, op1); tree inverted = invert_truthvalue_loc (loc, cond); - bool can_infer_simple_equiv - = !(HONOR_SIGNED_ZEROS (op0) - && real_zerop (op0)); + bool can_infer_simple_equiv + = !(HONOR_SIGNED_ZEROS (op0) && real_maybe_zerop (op0)) + && !DECIMAL_FLOAT_MODE_P (element_mode (TREE_TYPE (op0))); class edge_info *edge_info; edge_info = new class edge_info (true_edge); @@ -639,9 +639,9 @@ record_edge_info (basic_block bb) { tree cond = build2 (code, boolean_type_node, op0, op1); tree inverted = invert_truthvalue_loc (loc, cond); - bool can_infer_simple_equiv - = !(HONOR_SIGNED_ZEROS (op1) - && (TREE_CODE (op1) == SSA_NAME || real_zerop (op1))); + bool can_infer_simple_equiv + = !(HONOR_SIGNED_ZEROS (op1) && real_maybe_zerop (op1)) + && !DECIMAL_FLOAT_MODE_P (element_mode (TREE_TYPE (op1))); class edge_info *edge_info; edge_info = new class edge_info (true_edge); --- gcc/testsuite/gcc.dg/dfp/pr108068.c.jj 2022-12-21 16:41:45.243738850 +0100 +++ gcc/testsuite/gcc.dg/dfp/pr108068.c 2022-12-21 16:41:38.267839223 +0100 @@ -0,0 +1,14 @@ +/* PR tree-optimization/108068 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +int +main () +{ + _Decimal64 x = -1; + while (x != 0) + x /= 10; + double d = x; + if (!__builtin_signbit (d)) + __builtin_abort (); +}