Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2194100/?format=api
{ "id": 2194100, "url": "http://patchwork.ozlabs.org/api/patches/2194100/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/004601dc97aa$270c3c20$7524b460$@nextmovesoftware.com/", "project": { "id": 17, "url": "http://patchwork.ozlabs.org/api/projects/17/?format=api", "name": "GNU Compiler Collection", "link_name": "gcc", "list_id": "gcc-patches.gcc.gnu.org", "list_email": "gcc-patches@gcc.gnu.org", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<004601dc97aa$270c3c20$7524b460$@nextmovesoftware.com>", "list_archive_url": null, "date": "2026-02-06T20:49:55", "name": "PR tree-optimization/123958: FMA vs pow(x,2.0) [vs errno]", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "bfb47fa723571b3746725c55367e5edc223a1151", "submitter": { "id": 68376, "url": "http://patchwork.ozlabs.org/api/people/68376/?format=api", "name": "Roger Sayle", "email": "roger@nextmovesoftware.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/004601dc97aa$270c3c20$7524b460$@nextmovesoftware.com/mbox/", "series": [ { "id": 491332, "url": "http://patchwork.ozlabs.org/api/series/491332/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=491332", "date": "2026-02-06T20:49:55", "name": "PR tree-optimization/123958: FMA vs pow(x,2.0) [vs errno]", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/491332/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2194100/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2194100/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "gcc-patches@gcc.gnu.org" ], "Delivered-To": [ "patchwork-incoming@legolas.ozlabs.org", "gcc-patches@gcc.gnu.org" ], "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com\n header.a=rsa-sha256 header.s=default header.b=lUougMxb;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)", "sourceware.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key,\n unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com\n header.a=rsa-sha256 header.s=default header.b=lUougMxb", "sourceware.org; dmarc=pass (p=none dis=none)\n header.from=nextmovesoftware.com", "sourceware.org;\n spf=pass smtp.mailfrom=nextmovesoftware.com", "server2.sourceware.org;\n arc=none smtp.remote-ip=69.48.154.134" ], "Received": [ "from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4f75ny19Wdz1xvD\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 07 Feb 2026 07:50:30 +1100 (AEDT)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 143F54BAD16D\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 6 Feb 2026 20:50:28 +0000 (GMT)", "from server.nextmovesoftware.com (server.nextmovesoftware.com\n [69.48.154.134])\n by sourceware.org (Postfix) with ESMTPS id 94D304BA2E0B\n for <gcc-patches@gcc.gnu.org>; Fri, 6 Feb 2026 20:49:57 +0000 (GMT)", "from [168.86.198.35] (port=53378 helo=Dell)\n by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls\n TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.99.1)\n (envelope-from <roger@nextmovesoftware.com>)\n id 1voSm4-00000009SUQ-1my6; Fri, 06 Feb 2026 15:49:56 -0500" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 143F54BAD16D", "OpenDKIM Filter v2.11.0 sourceware.org 94D304BA2E0B" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 94D304BA2E0B", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 94D304BA2E0B", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770410997; cv=none;\n b=Auw/cQFR/nrQlDkNkIxAmlBzZJeJCs4KGkx+5vTkClGASILqL2YeZMDYevAqDD4gCFkTvDJwttnrgWId+axQtK4jfMdepDQ1/WvehJknWlBFZc1GDDLQsruU2H+XhBKuBuslDIZjmOL/fuBc309xYndxNF1eYxwqLV0wEBoMv44=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1770410997; c=relaxed/simple;\n bh=tTGAXI+LjsXy1vBUvOhVJg+5J0GnhMStDhF/bHj3Q+U=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=dary3A4uJgzN1GFSqU0QlsDrGm454VLm2GGuonXriPP38J1hjj+C4lKryyGfL5olfPPbDL0RvwBfWXNDVXRoztzRYfq37CgV1l7Qrgq5OacSJOCxT5nW9TjFnWqLMV2PBr8SXEe7DwH9NQi3f4q1dlT7CBl34u2/UxbZAQCW2us=", "ARC-Authentication-Results": "i=1; server2.sourceware.org", "DKIM-Signature": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID:\n Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID:\n Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:\n List-Subscribe:List-Post:List-Owner:List-Archive;\n bh=xvBYd7/aL5boj7vwwSbHbsBZuJfH0qAVGNEi0utVHOo=; b=lUougMxbM74cVkKygTljjOlElA\n wXBYvVsI83d1Rw+TB8uKwcQ2jCYSjhRkGN3kPDuvXFuTk4u80VA97lJzKSOVCgZC4s8SYAbt0iimX\n AUpJr91/gn9R6NOyiSTQ1IcAUYsyPgeciq61hDbIO9D90SZMEIU3mFrDQxKwNBELTEByZnk4KZO4R\n VNbEMF9+a1hEYoficOjeESODtTbJrJWNAMVOvTVFYkdP8sCfiOy6LJSmf4nT/TYMW1DvLCvR9hYkZ\n mOxOrm5W5wWGwF7KnGPYyDk3VpgN2sQDbJMNizdjcJooltLpf++ZsCtv1Ix+Mpi1l2cwqDerzypHW\n M0B4EmZw==;", "From": "\"Roger Sayle\" <roger@nextmovesoftware.com>", "To": "\"'GCC Patches'\" <gcc-patches@gcc.gnu.org>", "Cc": "\"'Jakub Jelinek'\" <jakub@redhat.com>", "Subject": "[PATCH] PR tree-optimization/123958: FMA vs pow(x,2.0) [vs errno]", "Date": "Fri, 6 Feb 2026 20:49:55 -0000", "Message-ID": "<004601dc97aa$270c3c20$7524b460$@nextmovesoftware.com>", "MIME-Version": "1.0", "Content-Type": "multipart/mixed;\n boundary=\"----=_NextPart_000_0047_01DC97AA.270C3C20\"", "X-Mailer": "Microsoft Outlook 16.0", "Thread-Index": "AdyXqNzRkAeFICOfR9yMbAiiMbyHew==", "Content-Language": "en-gb", "X-AntiAbuse": [ "This header was added to track abuse,\n please include it with any abuse report", "Primary Hostname - server.nextmovesoftware.com", "Original Domain - gcc.gnu.org", "Originator/Caller UID/GID - [47 12] / [47 12]", "Sender Address Domain - nextmovesoftware.com" ], "X-Get-Message-Sender-Via": "server.nextmovesoftware.com: authenticated_id:\n roger@nextmovesoftware.com", "X-Authenticated-Sender": "server.nextmovesoftware.com:\n roger@nextmovesoftware.com", "X-Source": "", "X-Source-Args": "", "X-Source-Dir": "", "X-BeenThere": "gcc-patches@gcc.gnu.org", "X-Mailman-Version": "2.1.30", "Precedence": "list", "List-Id": "Gcc-patches mailing list <gcc-patches.gcc.gnu.org>", "List-Unsubscribe": "<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>", "List-Archive": "<https://gcc.gnu.org/pipermail/gcc-patches/>", "List-Post": "<mailto:gcc-patches@gcc.gnu.org>", "List-Help": "<mailto:gcc-patches-request@gcc.gnu.org?subject=help>", "List-Subscribe": "<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>", "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org" }, "content": "This is my proposed solution to PR123958 (and PR124002) which is a\nregression exposed by my recent change to avoid expanding pow(x,2.0)\nto x*x with -fmath-errno (the default) when we can't guarantee that\nerrno shouldn't be updated. The problem is that the logic to convert\npow(x,2.0) was also duplicated (but unused) in tree-ssa-math-opts\nwhere it's intended to perform this conversion in order to expose\nfused-multiply-add instructions when supported by the target. The\nissue is that this \"vestigial\" code has bit-rotten over the years,\nand incorrectly updates vdefs when changing vops, tiggering an ICE.\n\nMy pragmatic solution to this is to simply delete the problematic\ncode; the decision of whether pow(x,2.0) should be expanded is left\nto the earlier pow_expand pass (which is what it's designed for), and\nthe later FMA pass can make use of any resulting FP multiplications.\nNot only does this avoid the PHI related ICE, but also fixes the\noriginal PR (on updating errno) on targets with FMA, e.g. aarch64\nand recent x86_64 architectures (such as -march=znver3).\n\n\nThis patch has been tested on x86_64-pc-linux-gnu with make bootstrap\nand make -k check, both with and without --target_board=unix{-m32},\nwith no new failures. Ok for mainline?\n\n\n2026-02-06 Roger Sayle <roger@nextmovesoftware.com>\n\ngcc/ChangeLog\n\tPR middle-end/123826\n\tPR tree-optimization/123958\n\tPR c++/124002\n\t* tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children):\n\tDelete code that (mis)handled conversion of pow(x,2.0) to x*x.\n\ngcc/testsuite/ChangeLog\n\tPR middle-end/123826\n\tPR tree-optimization/123958\n\tPR c++/124002\n\t* g++.target/i386/pr124002.C: New test case.\n\t* gcc.target/i386/pr123958.c: Likewise.\n\t* gcc.dg/errno-4.c: Likewise.\n\n\nRoger\n--", "diff": "diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc\nindex 469de10a432..5947c8ab184 100644\n--- a/gcc/tree-ssa-math-opts.cc\n+++ b/gcc/tree-ssa-math-opts.cc\n@@ -6597,25 +6597,6 @@ math_opts_dom_walker::after_dom_children (basic_block bb)\n \t{\n \t switch (gimple_call_combined_fn (stmt))\n \t {\n-\t CASE_CFN_POW:\n-\t if (gimple_call_lhs (stmt)\n-\t\t && TREE_CODE (gimple_call_arg (stmt, 1)) == REAL_CST\n-\t\t && real_equal (&TREE_REAL_CST (gimple_call_arg (stmt, 1)),\n-\t\t\t\t &dconst2)\n-\t\t && convert_mult_to_fma (stmt,\n-\t\t\t\t\t gimple_call_arg (stmt, 0),\n-\t\t\t\t\t gimple_call_arg (stmt, 0),\n-\t\t\t\t\t &fma_state))\n-\t\t{\n-\t\t unlink_stmt_vdef (stmt);\n-\t\t if (gsi_remove (&gsi, true)\n-\t\t && gimple_purge_dead_eh_edges (bb))\n-\t\t *m_cfg_changed_p = true;\n-\t\t release_defs (stmt);\n-\t\t continue;\n-\t\t}\n-\t break;\n-\n \t case CFN_COND_MUL:\n \t if (convert_mult_to_fma (stmt,\n \t\t\t\t gimple_call_arg (stmt, 1),\ndiff --git a/gcc/testsuite/g++.target/i386/pr124002.C b/gcc/testsuite/g++.target/i386/pr124002.C\nnew file mode 100644\nindex 00000000000..033cd3de870\n--- /dev/null\n+++ b/gcc/testsuite/g++.target/i386/pr124002.C\n@@ -0,0 +1,15 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O2 -march=znver3\" } */\n+\n+extern \"C\" double pow(double, double);\n+double sigmoid_x;\n+double sigmoid() {\n+ if (sigmoid_x)\n+ return sigmoid_x;\n+ return 0;\n+}\n+double der_sigmoid() {\n+ double tmp = sigmoid();\n+ return tmp - pow(tmp, 2);\n+}\n+\ndiff --git a/gcc/testsuite/gcc.target/i386/pr123958.c b/gcc/testsuite/gcc.target/i386/pr123958.c\nnew file mode 100644\nindex 00000000000..75064e880b4\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/i386/pr123958.c\n@@ -0,0 +1,18 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O3 -march=znver3\" } */\n+\n+float fnk00xX_rae1_1;\n+double pow(double, double);\n+double sqrt(double);\n+void write_r4(float *);\n+void fnk00xX() {\n+ int i;\n+ float rs2;\n+ double ds2;\n+ for (; i; i += 1) {\n+ sqrt(i);\n+ ds2 = ds2 + pow(fnk00xX_rae1_1, 2.0);\n+ rs2 = ds2;\n+ }\n+ write_r4(&rs2);\n+}\ndiff --git a/gcc/testsuite/gcc.dg/errno-4.c b/gcc/testsuite/gcc.dg/errno-4.c\nnew file mode 100644\nindex 00000000000..d7b80c1ca41\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/errno-4.c\n@@ -0,0 +1,35 @@\n+/* PR middle-end/123826 */\n+/* { dg-do run } */\n+/* { dg-options \"-O2\" } */\n+\n+#ifdef __NO_MATH_ERRNO__\n+int main() { return 0; }\n+#else\n+#include <errno.h>\n+#include <float.h>\n+#include <math.h>\n+\n+double foo(double x)\n+{\n+ return x + pow(x, 2.0);\n+}\n+\n+int main()\n+{\n+#ifdef math_errhandling\n+#ifdef MATH_ERRNO\n+ if ((math_errhandling & MATH_ERRNO) == 0)\n+ return 0;\n+#else\n+ if ((math_errhandling & 1) == 0)\n+ return 0;\n+#endif\n+#endif\n+\n+ errno = 0;\n+ double x = foo(DBL_MAX);\n+ if (errno != ERANGE)\n+ __builtin_abort ();\n+ return 0;\n+}\n+#endif\n", "prefixes": [] }