From patchwork Wed Jul 31 13:40:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1967116 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=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=tVk49GhC; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=kgCXEZU4; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=tVk49GhC; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=kgCXEZU4; 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 4WYtXB4YMMz1ybb for ; Wed, 31 Jul 2024 23:40:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DFDDB385843B for ; Wed, 31 Jul 2024 13:40:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 4045A3857011 for ; Wed, 31 Jul 2024 13:40:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4045A3857011 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4045A3857011 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722433217; cv=none; b=NIPM0tTLiJJIxdBWbJoOCvF3PvcI6Se8sfHpcHTBGLSHbDCgQsBlJ4soUs2LFhoWnqGgQSySTFzUX4surt2vLwDT50jZhin3HR7YK47hAS1hiO0Kwb8Qc7iYocPLd8QBQ61Ol/vdc9c2J+P8TLPgYabawojGdvwbAVYESXEp/gg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722433217; c=relaxed/simple; bh=XxvsaSPONuxn3HvzGET1yDZNlRLMXyUrqfOfVT/tq64=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=Q3ija0PABCVH75W8Ctf3fGLzyMqTtXkCpA7SbjvGADJpfT7n4i62j+EXiyb/tGw8RrksktPJb611xMfM1HmTsIOs+y0A7NmDmmBJr3gvmDgV/iyQmxqA6J46ZhVrrzRKOhtXbzK2g2mPCk1S4TqH8YjsCBcWjQ2VChyo2ODnVJ8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3E58E21A49 for ; Wed, 31 Jul 2024 13:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722433215; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Z48KjIfMPCphxvnFKXbkmMeiuhVwpkXgGkIakhDGyYo=; b=tVk49GhC/xhE79xnivgAa67PCatJBIW46beRLG1QSOBVFcq5rpWiW5QPW9OCN2fZtYb2Yk AXtRc6RTjHZ/+RI0uT/DAs2nYvNNrSy+YhOo8nWYOT+qb8IJuppIpY/bt0Vn6K/XvMfxXp 1JcL3xhxSnxtUyFHqsxqI59ihaf4h5I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722433215; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Z48KjIfMPCphxvnFKXbkmMeiuhVwpkXgGkIakhDGyYo=; b=kgCXEZU4nsmv7S1NZGz/yHqXXTAnqIJ1L9U/LJeEAdzqiU1zmTuCvkSme9VncdGMS/zBQY xTG1G2sOsJ9NiIBA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722433215; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Z48KjIfMPCphxvnFKXbkmMeiuhVwpkXgGkIakhDGyYo=; b=tVk49GhC/xhE79xnivgAa67PCatJBIW46beRLG1QSOBVFcq5rpWiW5QPW9OCN2fZtYb2Yk AXtRc6RTjHZ/+RI0uT/DAs2nYvNNrSy+YhOo8nWYOT+qb8IJuppIpY/bt0Vn6K/XvMfxXp 1JcL3xhxSnxtUyFHqsxqI59ihaf4h5I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722433215; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Z48KjIfMPCphxvnFKXbkmMeiuhVwpkXgGkIakhDGyYo=; b=kgCXEZU4nsmv7S1NZGz/yHqXXTAnqIJ1L9U/LJeEAdzqiU1zmTuCvkSme9VncdGMS/zBQY xTG1G2sOsJ9NiIBA== Date: Wed, 31 Jul 2024 15:40:15 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/3][v3] tree-optimization/114659 - VN and FP to int punning MIME-Version: 1.0 X-Spamd-Result: default: False [-1.06 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.46)[-0.457]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; MISSING_XM_UA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; MIME_TRACE(0.00)[0:+] X-Spam-Level: X-Spam-Score: -1.06 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20240731134040.DFDDB385843B@sourceware.org> The following addresses another case where x87 FP loads mangle the bit representation and thus are not suitable for a representative in other types. VN was value-numbering a later integer load of 'x' as the same as a former float load of 'x'. We can use the new TARGET_MODE_CAN_TRANSFER_BITS hook to identify problematic modes and enforce strict compatibility for those in the reference comparison, improving the handling of modes with padding in visit_reference_op_load. PR tree-optimization/114659 * tree-ssa-sccvn.cc (visit_reference_op_load): Do not prevent punning from modes with padding here, but ... (vn_reference_eq): ... ensure this here, also honoring types with modes that cannot act as bit container. * gcc.target/i386/pr114659.c: New testcase. --- gcc/testsuite/gcc.target/i386/pr114659.c | 62 ++++++++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 11 ++--- 2 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr114659.c diff --git a/gcc/testsuite/gcc.target/i386/pr114659.c b/gcc/testsuite/gcc.target/i386/pr114659.c new file mode 100644 index 00000000000..e1e24d55687 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr114659.c @@ -0,0 +1,62 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +int +my_totalorderf (float const *x, float const *y) +{ + int xs = __builtin_signbit (*x); + int ys = __builtin_signbit (*y); + if (!xs != !ys) + return xs; + + int xn = __builtin_isnan (*x); + int yn = __builtin_isnan (*y); + if (!xn != !yn) + return !xn == !xs; + if (!xn) + return *x <= *y; + + unsigned int extended_sign = -!!xs; + union { unsigned int i; float f; } xu = {0}, yu = {0}; + __builtin_memcpy (&xu.f, x, sizeof (float)); + __builtin_memcpy (&yu.f, y, sizeof (float)); + return (xu.i ^ extended_sign) <= (yu.i ^ extended_sign); +} + +static float +positive_NaNf () +{ + float volatile nan = 0.0f / 0.0f; + return (__builtin_signbit (nan) ? - nan : nan); +} + +typedef union { float value; unsigned int word[1]; } memory_float; + +static memory_float +construct_memory_SNaNf (float quiet_value) +{ + memory_float m; + m.value = quiet_value; + m.word[0] ^= (unsigned int) 1 << 22; + m.word[0] |= (unsigned int) 1; + return m; +} + +memory_float x[7] = + { + { 0 }, + { 1e-5 }, + { 1 }, + { 1e37 }, + { 1.0f / 0.0f }, + }; + +int +main () +{ + x[5] = construct_memory_SNaNf (positive_NaNf ()); + x[6] = (memory_float) { positive_NaNf () }; + if (! my_totalorderf (&x[5].value, &x[6].value)) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index dc377fa16ce..0639ba426ff 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -837,6 +837,9 @@ vn_reference_eq (const_vn_reference_t const vr1, const_vn_reference_t const vr2) TYPE_VECTOR_SUBPARTS (vr2->type))) return false; } + else if (TYPE_MODE (vr1->type) != TYPE_MODE (vr2->type) + && !mode_can_transfer_bits (TYPE_MODE (vr1->type))) + return false; i = 0; j = 0; @@ -5814,13 +5817,7 @@ visit_reference_op_load (tree lhs, tree op, gimple *stmt) if (result && !useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (op))) { - /* Avoid the type punning in case the result mode has padding where - the op we lookup has not. */ - if (TYPE_MODE (TREE_TYPE (result)) != BLKmode - && maybe_lt (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (result))), - GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (op))))) - result = NULL_TREE; - else if (CONSTANT_CLASS_P (result)) + if (CONSTANT_CLASS_P (result)) result = const_unop (VIEW_CONVERT_EXPR, TREE_TYPE (op), result); else {