{"id":2224800,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2224800/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260418190251.2258174-1-andrew.pinski@oss.qualcomm.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/projects/17/?format=json","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},"msgid":"<20260418190251.2258174-1-andrew.pinski@oss.qualcomm.com>","date":"2026-04-18T19:02:51","name":"[GCC17-PATCH] phiopt: Remove 2 preds restriction on factor [PR123113]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"d69663b8053142431a3ecfe38738683423a1f71e","submitter":{"id":91428,"url":"http://patchwork.ozlabs.org/api/1.1/people/91428/?format=json","name":"Andrew Pinski","email":"andrew.pinski@oss.qualcomm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260418190251.2258174-1-andrew.pinski@oss.qualcomm.com/mbox/","series":[{"id":500461,"url":"http://patchwork.ozlabs.org/api/1.1/series/500461/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500461","date":"2026-04-18T19:02:51","name":"[GCC17-PATCH] phiopt: Remove 2 preds restriction on factor [PR123113]","version":1,"mbox":"http://patchwork.ozlabs.org/series/500461/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224800/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2224800/checks/","tags":{},"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=pass (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=eJ7br7b5;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=AYpkfrFz;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=temperror (SPF Temporary Error: DNS Timeout) 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=pass (2048-bit key,\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=eJ7br7b5;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=AYpkfrFz","sourceware.org; dmarc=none (p=none dis=none)\n header.from=oss.qualcomm.com","sourceware.org;\n spf=pass smtp.mailfrom=oss.qualcomm.com","server2.sourceware.org;\n arc=none smtp.remote-ip=205.220.180.131"],"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 4fyh4B2lkpz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 19 Apr 2026 05:03:33 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 827D74B920A7\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 19:03:29 +0000 (GMT)","from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n [205.220.180.131])\n by sourceware.org (Postfix) with ESMTPS id 0C33B4BAD142\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 19:02:59 +0000 (GMT)","from pps.filterd (m0279868.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63IH027Z2794397\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 19:02:58 GMT","from mail-pl1-f197.google.com (mail-pl1-f197.google.com\n [209.85.214.197])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dm19fsdj6-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 19:02:58 +0000 (GMT)","by mail-pl1-f197.google.com with SMTP id\n d9443c01a7336-2b4654f9bb6so18786635ad.2\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 12:02:58 -0700 (PDT)","from xeond2.wrightpinski.org ([98.97.34.2])\n by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b5fab0cf3bsm67079765ad.44.2026.04.18.12.02.55\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Sat, 18 Apr 2026 12:02:55 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 827D74B920A7","OpenDKIM Filter v2.11.0 sourceware.org 0C33B4BAD142"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 0C33B4BAD142","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 0C33B4BAD142","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776538979; cv=none;\n b=lmcOaoYIqnrxSiM11duB29ZTi3RK15iJadlVVlax1NUzkNIGuBlA533XaAzXP0EqZNlKdKtqx0hYl62FdTNmMgu36WFU4OF8KzfUC4Ge7yN74Hgv5UJR7RJv3JMzwnY5n4Gb/cqPiwcrpBUQEgBtTHbuKIWyQCc0hqyIrzqVVGE=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776538979; c=relaxed/simple;\n bh=q7TVANYdCL6woYkBkfGpmOfLgMtEVYQq9LEJd13vGm8=;\n h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID:\n MIME-Version;\n b=FiHBrTClbq78sq256ZOQe/dg5byJHE9AFd3hccMdV03efmQVP6pCyDel0X0IsJLm9tdKsWBQQNHQ8kZzsY8X4NBEBiFl+IjuyL8wzEg0TrPEIfqeEAf1cFLfv8833nKwvJsnDsm+WwNS/BElxq7Z2BlhDkZlFOAkeDESvWw7nfw=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:date:from:message-id:mime-version\n :subject:to; s=qcppdkim1; bh=3SgCkYHy5o3SQAfXAnOhoLK9B3phjMaKkOc\n fdCrqiSU=; b=eJ7br7b5XFgS2rpweMfmK9jAf+ksuOXkIWBDSoCTzfwOLgORC6+\n Yd/t6ez1d2tM96rsdC9b0qheaaJ97PX2rADf2pwXl0lAdrMntpc+JOuFdf44l1U/\n RGQ1wBt4HKl6vxn96hlbtCAFtZXeEX4CHG4IfFZbGDLX5Y7OpK72YtLAu01jhWtN\n Ffv4A6hNQlyrSiDSgHwuNCb+aX6WnNqHsBHd7kMz0eOdXQTOxywKzcWSGC+B2kBk\n yxT8o8Oc1CFzMgz6IDhHZKa+1BW7xwrAX1vq0jCFuKpE1QPJM+35GCXBN97bqc7b\n UWWGhfSzC/L2hT1KrzPmJP0R+iJMUhCgd0w==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1776538977; x=1777143777; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:from:to:cc:subject:date:message-id:reply-to;\n bh=3SgCkYHy5o3SQAfXAnOhoLK9B3phjMaKkOcfdCrqiSU=;\n b=AYpkfrFz8CHaPfQsry8jD2yVMY4QuZkz42CK6Rx3BVZTKcGc4Z7iGeFTKahNb9+EmG\n mi7w72rszIt9AyaX+NTLa6dMiRkQT04zy4OmimSmG8Gwpmfg59gRFWA9s0TI8+Cfandq\n Z7V/bcxb7+DQ4PuFMV0vmB1HdZJeZy327ZZr1mTI1OqtXWiVYyuk1xSYTWRnMr8y5+K0\n QwID6Q7URC0DNgofP0mLGQ8frnbji1SAK0662x6ENPoEY1gqWu7xfETUlfPb1UYe0IhG\n 8sXgq/WsR5RmAFvBSasaiX+P9S3CrC8dXvLfR1Kd+2NOS1lvHDM23ZnznoDo1s4ZcUct\n nFSA=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776538977; x=1777143777;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=3SgCkYHy5o3SQAfXAnOhoLK9B3phjMaKkOcfdCrqiSU=;\n b=m3XUy5t/X+yrth5svsczoVxbdxIOVJ5+TOXsUoI+M1vVhGhyFzYvsxHL4pU4r97JDG\n s1z9qJ4388f99R2vMmxc2OlxUaQ0W/VOFEgyazn2tagquAJsgE17rR0VLmAHagX3B7+0\n dPXAPH2Mt9uvVpZbuq8RGlLVeAG+DexzIjpxb7S0xLBDjOCUYFJ+Ex39bYAD59cNKDsm\n XqqUPDcEgvaEV8nB6JCZNe2s57BS0v2cQVwdJA7rbaA3Wq9FbSPb35+mgm/kEaY+4Moc\n mnL17v0e52GnPajjIMHbC7V0PBY3mE3DzyYGcNqyjBveqxvO6wpF0J5CAPzgngN/hMwh\n iqQQ==","X-Gm-Message-State":"AOJu0YxP1CM0gXdPqXv1vN39lS2q0Rsf6Lv0R/EkzyBc4jtsD5B/OnTc\n vA/wESZlEJxtDkPSML3QZUG3V01HHzyHj+NHn6VDvV7mG7ysQtH5In8Bs8BMkRYNsKtFOjzKfMn\n Xr1nUKJOAnj3nWTIJv7tR5jFNnbZn+lDnSib6PuHKJARya5kc6vFQofpH0YbGfH++NRZh","X-Gm-Gg":"AeBDieu9tSu3/KJDt97mPSt1oR9bNm3YKonNiuIO8VjjLXi6ScEufVQiSzP+NbeOo34\n LTIlyblbisGT/7rdX6kQLnxD04LkhytlrPIsxKs1z6MJp9h0lrDiCr2iPNLEGdFph3nYkAiD4tM\n Dt60FoYPxlpL85liiNC4X0iPgel5HAqbaZJi9J4w5QjuD0pp7Q77TwltGS5kt2wRTolh6xPyWMV\n cXfUJ6WEO+xDCGiGPJxrDpIM4KStrn9jz6Cjo8iuQ1uvWIQDFhNr1I3QEUUEDtPMpc0KIHpL6Wk\n LmJtN5MBOsEujo6sgL2OAmlGoYl4/H1HoI6Ar/j2SFFXfOFUkfzDpunUvMWz8YVTsGIPV+rSZYI\n LzpeXRmoROvzlHHkPADLrvqeZm24NX7At1hKI2vJ/1NqVUxthL89A6cTs","X-Received":["by 2002:a17:902:aa98:b0:2b4:5cb8:99eb with SMTP id\n d9443c01a7336-2b5f9f8808amr60090675ad.27.1776538976694;\n Sat, 18 Apr 2026 12:02:56 -0700 (PDT)","by 2002:a17:902:aa98:b0:2b4:5cb8:99eb with SMTP id\n d9443c01a7336-2b5f9f8808amr60090565ad.27.1776538976030;\n Sat, 18 Apr 2026 12:02:56 -0700 (PDT)"],"From":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","To":"gcc-patches@gcc.gnu.org","Cc":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Subject":"[GCC17-PATCH] phiopt: Remove 2 preds restriction on factor [PR123113]","Date":"Sat, 18 Apr 2026 12:02:51 -0700","Message-ID":"<20260418190251.2258174-1-andrew.pinski@oss.qualcomm.com>","X-Mailer":"git-send-email 2.43.0","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDE4MDE5MCBTYWx0ZWRfX3J1YkoPgMWdq\n qnVOEdWZSFeXYy47++2ELo+rizgHm/wba3k3l3IYOKaBnVi2/VtgmBWHblKzCUFkPyNufECnB87\n 6OBATZD+2CJFdsvr+z2UtD0vKdou+VnGYT9yDBQZQj28RysnO5IDsXXgjA/z+wwXpF5VDPOaHRY\n w0VFMFP9dK80F9PrGq3hD1CFiiRp17tR/R4+O21Vo1PTUllR+ougu89Wokq0ga2E2E/9H8rwBBz\n NvM/wcL7EAHp8D6bDvQeHEDeBk/mEF7BVr1MJP8yJSaTgKsTftGD1FbrY/P5P991ofAoSkthidu\n 5G0rQTWiuLnGeHrdDbjGaBfbUUL784U+xnprUV50yN3dNFTrahcaUvYx3dAKrN00PB0Tiqy2EDh\n toyY6XwBa+IhKK9t7wDfpXhO7dBGKuFgvQUfU3NLKAptTf0almo2EDTIKj2rBFK/bytnlqNK6FV\n 31GtWxDI8pgUTyFKGSg==","X-Proofpoint-ORIG-GUID":"HTFFUODsNLow9phhMCaE-ya81cJDuGKn","X-Proofpoint-GUID":"HTFFUODsNLow9phhMCaE-ya81cJDuGKn","X-Authority-Analysis":"v=2.4 cv=FMorAeos c=1 sm=1 tr=0 ts=69e3d562 cx=c_pps\n a=cmESyDAEBpBGqyK7t0alAg==:117 a=yb6njnUeU2jdBzxOxKIisA==:17\n a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22\n a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=EUspDBNiAAAA:8\n a=O7lXdu8sfXsptR7lgMkA:9 a=1OuFwYUASf3TG4hYMiVC:22","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-18_05,2026-04-17_04,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n bulkscore=0 spamscore=0 priorityscore=1501 phishscore=0 adultscore=0\n clxscore=1015 suspectscore=0 lowpriorityscore=0 impostorscore=0\n malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc=\n route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604070000\n definitions=main-2604180190","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":"Like the previous patches but this is for factoring out operations.\nThere needs some extra work needed to be handled here due to the\nresult of the phi changing after the creating the fowarder block.\nWe need to update the lhs of the last statement in the sequence to\nwhat the phi is.\n\nphi_on_compare-3.c needed to be updated since phiopt factors out\na cast and now dom2 does one  jump threading instead of 3. Note\nthe code is better in the end. And does not delete a basic-block\nbut instead merges 2.\nssa-dom-thread-16.c needs to disable phiopt as we factor out a cast\nand now can combine one more pair of if statements. This testcase\nalready disables passes so I thought it was ok to do that too.\n\nBootstrapped and tested on x86_64-linux-gnu.\n\n\tPR tree-optimization/123113\ngcc/ChangeLog:\n\n\t* tree-ssa-phiopt.cc (edges_split): Move earlier.\n\t(make_forwarder): Likewise.\n\t(factor_out_conditional_operation): Handle more than\n\t2 predecessors.\n\t(pass_phiopt::execute): Don't restrict factoring on\n\t2 predecessors.\n\ngcc/testsuite/ChangeLog:\n\n\t* gcc.dg/tree-ssa/phi_on_compare-3.c: Update testcase.\n\t* gcc.dg/tree-ssa/ssa-dom-thread-16.c: Add -fno-ssa-phiopt.\n\t* gcc.dg/tree-ssa/phi-opt-factor-2.c: New test.\n\nSigned-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>\n---\n .../gcc.dg/tree-ssa/phi-opt-factor-2.c        | 31 +++++++\n .../gcc.dg/tree-ssa/phi_on_compare-3.c        |  5 +-\n .../gcc.dg/tree-ssa/ssa-dom-thread-16.c       |  4 +-\n gcc/tree-ssa-phiopt.cc                        | 91 ++++++++++---------\n 4 files changed, 85 insertions(+), 46 deletions(-)\n create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-factor-2.c","diff":"diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-factor-2.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-factor-2.c\nnew file mode 100644\nindex 00000000000..8282e6604b8\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-factor-2.c\n@@ -0,0 +1,31 @@\n+/* { dg-options \"-O2 -fdump-tree-phiopt\" } */\n+\n+/* PR tree-optimization/116699\n+   PR tree-optimization/123113\n+   Make sure the return PREDICT has no factor in deciding\n+   if we factor out the conversion.\n+   Also check that we can do the factoring even if there are\n+   more than 2 predecessors.   */\n+\n+short f0(int a, int b, int c, int d)\n+{\n+  if (d) return 1234;\n+  int t1 = 4;\n+  if (c < t1)  return (c > -1 ? c : -1);\n+  return t1;\n+}\n+\n+\n+short f1(int a, int b, int c, int d)\n+{\n+  if (d) return 1234;\n+  int t1 = 4;\n+  short t = t1;\n+  if (c < t1)  t = (c > -1 ? c : -1);\n+  return t;\n+}\n+\n+/* Both f1 and f0  should be optimized at phiopt1 to the same thing. */\n+/* { dg-final { scan-tree-dump-times \"MAX_EXPR \" 2 \"phiopt1\" } } */\n+/* { dg-final { scan-tree-dump-times \"MIN_EXPR \" 2  \"phiopt1\" } } */\n+/* { dg-final { scan-tree-dump-times \"if \" 2 \"phiopt1\" } } */\ndiff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi_on_compare-3.c b/gcc/testsuite/gcc.dg/tree-ssa/phi_on_compare-3.c\nindex b48ecbf6e61..9e17b16a980 100644\n--- a/gcc/testsuite/gcc.dg/tree-ssa/phi_on_compare-3.c\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi_on_compare-3.c\n@@ -1,5 +1,5 @@\n /* { dg-do compile } */\n-/* { dg-options \"-Ofast -fdump-tree-dom2\" } */\n+/* { dg-options \"-Ofast -fdump-tree-dom2-details\" } */\n \n void g (void);\n void g1 (void);\n@@ -22,4 +22,5 @@ f (long a, long b, long c, long d, int x)\n     }\n }\n \n-/* { dg-final { scan-tree-dump-times \"Removing basic block\" 1 \"dom2\" } } */\n+/* { dg-final { scan-tree-dump-times \"Merging blocks\" 2 \"dom2\" } } */\n+/* { dg-final { scan-tree-dump-times \"Threaded jump\" 1 \"dom2\" } } */\ndiff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-16.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-16.c\nindex e8555f2d963..d180d4cff5d 100644\n--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-16.c\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-16.c\n@@ -1,5 +1,7 @@\n /* { dg-do compile } */\n-/* { dg-options \"-O2 -fdump-tree-dom2-details -w --param logical-op-non-short-circuit=1 -fdisable-tree-threadfull1\" } */\n+/* { dg-options \"-O2 -fdump-tree-dom2-details -w --param logical-op-non-short-circuit=1 -fdisable-tree-threadfull1 -fno-ssa-phiopt\" } */\n+/* Disable phiopt to disable factoring of a cast from bool to `unsigned char` which removes\n+   a jump threading opportunity as we instead have `a & b`.  */\n unsigned char\n validate_subreg (unsigned int offset, unsigned int isize, unsigned int osize, int zz, int qq)\n {\ndiff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc\nindex ac75e117ad3..bdc807bca75 100644\n--- a/gcc/tree-ssa-phiopt.cc\n+++ b/gcc/tree-ssa-phiopt.cc\n@@ -299,6 +299,42 @@ is_factor_profitable (gimple *def_stmt, basic_block merge, tree arg)\n   return true;\n }\n \n+/* Callback function for make_forwarder_block,\n+   returns true if the edge src is either of\n+   the 2 basic blocks in the array BBS (DATA). */\n+\n+static bool\n+edges_split (edge e, void *data)\n+{\n+  basic_block *bbs = (basic_block*)data;\n+  return e->src == bbs[0] || e->src == bbs[1];\n+}\n+\n+\n+/* Makes a forwarder block for JOIN_BB such that\n+   THEN_BB and ELSE_BB are the only 2 predecessors\n+   of the block. Note the JOIN_BB is required to be\n+   the same and the PHI nodes of JOIN_BB have to be\n+   the same too.  */\n+\n+static void\n+make_forwarder (basic_block then_bb, basic_block else_bb,\n+\t\tbasic_block join_bb)\n+{\n+  basic_block bbs[2];\n+\n+  /* If the join block already has 2 predecessors, then there\n+     is nothing to be done.  */\n+  if (EDGE_COUNT (join_bb->preds) == 2)\n+    return;\n+  bbs[0] = then_bb;\n+  bbs[1] = else_bb;\n+  edge ne = make_forwarder_block (join_bb, edges_split, bbs);\n+  gcc_assert (join_bb == ne->src);\n+  statistics_counter_event (cfun, \"if-then-else split for inserting common\", 1);\n+}\n+\n+\n /* PR66726: Factor operations out of COND_EXPR.  If the arguments of the PHI\n    stmt are Unary operator, factor out the operation and perform the operation\n    to the result of PHI stmt.  COND_STMT is the controlling predicate.\n@@ -315,9 +351,6 @@ factor_out_conditional_operation (edge e0, edge e1, basic_block merge,\n   location_t locus = gimple_location (phi);\n   gimple_match_op arg0_op, arg1_op;\n \n-  /* We should only get here if the phi had two arguments.  */\n-  gcc_assert (gimple_phi_num_args (phi) == 2);\n-\n   /* Virtual operands are never handled. */\n   if (virtual_operand_p (gimple_phi_result (phi)))\n     return false;\n@@ -523,12 +556,22 @@ factor_out_conditional_operation (edge e0, edge e1, basic_block merge,\n       return false;\n     }\n \n+  /* Create a forwarder block for the common code if needed.  */\n+  if (EDGE_COUNT (merge->preds) != 2)\n+    {\n+      make_forwarder (e0->src, e1->src, merge);\n+      /* Update the last statement to set the correct result.  */\n+      gimple *last_seq = *gsi_last (seq);\n+      result = gimple_phi_result (phi);\n+      gimple_set_lhs (last_seq, result);\n+    }\n+\n   if (locus != UNKNOWN_LOCATION)\n     annotate_all_with_location (seq, locus);\n-  gsi = gsi_after_labels (gimple_bb (phi));\n+  gsi = gsi_after_labels (merge);\n   gsi_insert_seq_before (&gsi, seq, GSI_CONTINUE_LINKING);\n \n-  newphi = create_phi_node (temp, gimple_bb (phi));\n+  newphi = create_phi_node (temp, merge);\n \n   if (dump_file && (dump_flags & TDF_DETAILS))\n     {\n@@ -2755,43 +2798,6 @@ cond_removal_in_builtin_zero_pattern (basic_block cond_bb,\n   return true;\n }\n \n-/* Callback function for make_forwarder_block,\n-   returns true if the edge src is either of\n-   the 2 basic blocks in the array BBS (DATA). */\n-\n-static bool\n-edges_split (edge e, void *data)\n-{\n-  basic_block *bbs = (basic_block*)data;\n-  return e->src == bbs[0] || e->src == bbs[1];\n-}\n-\n-\n-/* Makes a forwarder block for JOIN_BB such that\n-   THEN_BB and ELSE_BB are the only 2 predecessors\n-   of the block. Note the JOIN_BB is required to be\n-   the same and the PHI nodes of JOIN_BB have to be\n-   the same too.  */\n-\n-static void\n-make_forwarder (basic_block then_bb, basic_block else_bb,\n-\t\tbasic_block join_bb)\n-{\n-  basic_block bbs[2];\n-\n-  /* If the join block already has 2 predecessors, then there\n-     is nothing to be done.  */\n-  if (EDGE_COUNT (join_bb->preds) == 2)\n-    return;\n-  bbs[0] = then_bb;\n-  bbs[1] = else_bb;\n-  edge ne = make_forwarder_block (join_bb, edges_split, bbs);\n-  gcc_assert (join_bb == ne->src);\n-  statistics_counter_event (cfun, \"if-then-else split for inserting common\", 1);\n-}\n-\n-\n-\n /* Auxiliary functions to determine the set of memory accesses which\n    can't trap because they are preceded by accesses to the same memory\n    portion.  We do that for MEM_REFs, so we only need to track\n@@ -4111,7 +4117,6 @@ pass_phiopt::execute (function *)\n \n       /* Factor out operations from the phi if possible. */\n       if (single_pred_p (bb1)\n-\t  && EDGE_COUNT (merge->preds) == 2\n \t  && !optimize_debug)\n \t{\n \t  for (gsi = gsi_start (phis); !gsi_end_p (gsi); )\n","prefixes":["GCC17-PATCH"]}