{"id":2222239,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2222239/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260411004329.1762977-1-pengxuan.zheng@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":"<20260411004329.1762977-1-pengxuan.zheng@oss.qualcomm.com>","date":"2026-04-11T00:43:29","name":"cselim: Allow middle_bb to have more than one statement [PR124405]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"4754017bfef6d7cbb65d9143fe0684743a080b2a","submitter":{"id":92245,"url":"http://patchwork.ozlabs.org/api/1.1/people/92245/?format=json","name":"Pengxuan Zheng","email":"pengxuan.zheng@oss.qualcomm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260411004329.1762977-1-pengxuan.zheng@oss.qualcomm.com/mbox/","series":[{"id":499520,"url":"http://patchwork.ozlabs.org/api/1.1/series/499520/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=499520","date":"2026-04-11T00:43:29","name":"cselim: Allow middle_bb to have more than one statement [PR124405]","version":1,"mbox":"http://patchwork.ozlabs.org/series/499520/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2222239/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2222239/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=KxGkksAh;\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=bsbl3Pwj;\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=pass (2048-bit key,\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=KxGkksAh;\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=bsbl3Pwj","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 4fsw0R1Pcdz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 11 Apr 2026 10:44:05 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 740FC4BA2E1E\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 11 Apr 2026 00:44:03 +0000 (GMT)","from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n [205.220.180.131])\n by sourceware.org (Postfix) with ESMTPS id 7E56E4BA2E19\n for <gcc-patches@gcc.gnu.org>; Sat, 11 Apr 2026 00:43:34 +0000 (GMT)","from pps.filterd (m0279870.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63AHHdsk2047336\n for <gcc-patches@gcc.gnu.org>; Sat, 11 Apr 2026 00:43:33 GMT","from mail-dy1-f197.google.com (mail-dy1-f197.google.com\n [74.125.82.197])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dey77aa0x-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Sat, 11 Apr 2026 00:43:32 +0000 (GMT)","by mail-dy1-f197.google.com with SMTP id\n 5a478bee46e88-2c16233ee11so3570007eec.1\n for <gcc-patches@gcc.gnu.org>; Fri, 10 Apr 2026 17:43:32 -0700 (PDT)","from hu-pzheng-lv.qualcomm.com (Global_NAT1.qualcomm.com.\n [129.46.96.20]) by smtp.gmail.com with ESMTPSA id\n a92af1059eb24-12c3459faa7sm6485383c88.2.2026.04.10.17.43.29\n for <gcc-patches@gcc.gnu.org>\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 10 Apr 2026 17:43:29 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 740FC4BA2E1E","OpenDKIM Filter v2.11.0 sourceware.org 7E56E4BA2E19"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 7E56E4BA2E19","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 7E56E4BA2E19","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775868214; cv=none;\n b=EXK50V/UEzJJ+I0SW+L02yi4bDwbDR7UevhrgSsBCVHR2i8AppaF6PiJ1tl5eW12dhcUkYgZIhM/nzfinelfNkWb/bjBUuoQNAHU5pXXALmrSMCnuhzhaypn0GvWSSdN3noJXW85N24nj8iQzfmKdd019kl+wReciivfeUuya10=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775868214; c=relaxed/simple;\n bh=zC6vc6lL4gXS8v4Iq1swAGqWC19u1JyLs4idlfbAg1o=;\n h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id:\n MIME-Version;\n b=kMeJsKMrUi01x1xgtHiHm7/QTL72N+GbKshjOECrtBHdJyNgPMXz1ATIX/S9eF5oYwOgq5TwWw4nkn2YZgW5BwQhlmnHPLkS0kJp0qOD7CkQPtLDXMrZanSTVYNCDi20yW/0eu1ZS6txCeTF8tehR39SqwbRwRGwOELAKdYQ/Co=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n content-transfer-encoding:date:from:message-id:mime-version\n :subject:to; s=qcppdkim1; bh=7/wXNAfOnOiHziRUo3Rwt7Bt3wHIr5VEm+/\n xZ3QiPX4=; b=KxGkksAhg2h8ckHYyfmw3Uz18isP4rJzLsMr8j3IJKmhC5mQd2m\n mYKJ+Os9O5lks3FLAG9zmd1e3noDbReabdAQkIjOcHfSMztjlWfNptATj9WyXTxM\n sN1BuYG+V46azryFdbK/Nba07hauSIC6CttzLUd/yxnGzbOcDkG4g5LQQ2JvNJP8\n OxFT0E9ys8pfZenLwSFKMxGeSPfUaHncSozWx9nVwWwnHPzqoaYx/7FTaeLLVAY/\n hA9TGuWyree9H9gOLGPigKN14RpDLZSDUc0XdT3w/Uut82IQ/QQKrANLKI8uSqJW\n 4kuRss+0C4yN1F5O5fyibh85MK30NSdGcdQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1775868211; x=1776473011; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:message-id:date:subject:to\n :from:from:to:cc:subject:date:message-id:reply-to;\n bh=7/wXNAfOnOiHziRUo3Rwt7Bt3wHIr5VEm+/xZ3QiPX4=;\n b=bsbl3PwjEnfarBoILX9NpxcZGItqPVP0YhTRwe7/ZGoplJ8dIJKpVL25H15MHLXk3u\n 072kWhjrPKbMOfcyx6g0x3DM+itfY3sAKWrjdGolSvEkggDxoDhSzMmvnmTx/w6WKBbK\n tTg3c1veCgj0c517sCDDJ26IOfvA41akli6s88/bmfiytEq21YSOrRPCeHEzoNhvRMpO\n oRDl5/0oVb6ivj3ocDZD9c8IK8UVoUfsIVPwBY4knOxouJjz48/wkqHCSqXzsm50oAUP\n 56THFKKIYfN/1S71PlTr00/6rPT2cEB9LQRoybnORyKJSuK/fPypW8P2t0vGUVsJqkJC\n I30w=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775868211; x=1776473011;\n h=content-transfer-encoding:mime-version:message-id:date:subject:to\n :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=7/wXNAfOnOiHziRUo3Rwt7Bt3wHIr5VEm+/xZ3QiPX4=;\n b=MTR5LqkkyTyESuSwSO1f7LQS4iMhgWU8WBpqOvfeIj9wui2papCsgb/BJ5puUdyYMr\n d+zknp7VuB26u4kVmimic8fUH3Ffr4uM0CYiuz/as/nZZ3ETFDdbNdJgDlwYsz35XtbU\n ImEX3iS+QrQ2UfikffdRdWe18qjimvWIbNwlOt2hlF+8U2oHsmGsb5QziLTSS7Z7jU2/\n BNZlu931KgFe0KBb4QGnkJFiT+1TlzRClSMgqekXlol4ooPhY4o9TI7HyFKikwZn54r3\n HXnCMXf4B7t2tyFnpcFKNtbVpqP+1KweoCYWI3esaNlAPDkdlsdYPOBfc+9GIhvmH3uG\n kEuw==","X-Gm-Message-State":"AOJu0YxNx1pZEzvkhDM24HQvnQxUuLxP/QOPHE96REwhLZDFZmLA7Xbf\n xyGs7317ZDidSoc9HrLofGH1Mz8nCnCWB+2FprDhkA31SeKWitu6lNmAAVy7H0IvETJVvTmwi2H\n fV0bUcoMbcagi32siGfagqRyJix48+ulf4cZfA/X7nsadK4kt99CHBNO52KzOKf5fFCRq","X-Gm-Gg":"AeBDietKrm+uOD+2X0TZuvMs5MhqESbZfhRNrlXQGF8J19usEQaM0+WrwbMii7Mw0h4\n TNPjHyLxcF2PFB45DPc8rUnQNsSBn/ih7EdW/szD2/nSd8FEqDkVW3GExj66EJF6UnyNVqqIE31\n XvUgXcex9xL/GDKZ3KVHCHH6UdC6zKmYMOOiZGeAxWXUVu/ioPMRA0oUVz8CTR1BBiwMHhdk/b2\n YKHy2001YgRlKnur+ZfdyQ436tFGTnIqWddgnizG96rdemrqs+v/0za4RebU4KnzOsL6/CG/8if\n eTz5I5UO23WNuEbqEDTgSYusajoHNgxzZ+wltw0XuWTwC7bVVeaOMrfxPKoJJy9xXr63Pv1x2kh\n M7eZ8Unemtmi0zDL9R2zMeyyMjZ4dTMCUE3/hMkbjAX+yGMm3wWf2i1J9/Bjx8GumJYRludxAuH\n M9","X-Received":["by 2002:a05:7022:3d12:b0:119:e56c:18b1 with SMTP id\n a92af1059eb24-12c34eeb720mr2743433c88.25.1775868211133;\n Fri, 10 Apr 2026 17:43:31 -0700 (PDT)","by 2002:a05:7022:3d12:b0:119:e56c:18b1 with SMTP id\n a92af1059eb24-12c34eeb720mr2743415c88.25.1775868210322;\n Fri, 10 Apr 2026 17:43:30 -0700 (PDT)"],"From":"Pengxuan Zheng <pengxuan.zheng@oss.qualcomm.com>","To":"gcc-patches@gcc.gnu.org","Subject":"[PATCH] cselim: Allow middle_bb to have more than one statement\n [PR124405]","Date":"Fri, 10 Apr 2026 17:43:29 -0700","Message-Id":"<20260411004329.1762977-1-pengxuan.zheng@oss.qualcomm.com>","X-Mailer":"git-send-email 2.34.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Proofpoint-ORIG-GUID":"7CphYZJfcsZiV-NvYLwmKSSInW3gRNJI","X-Proofpoint-GUID":"7CphYZJfcsZiV-NvYLwmKSSInW3gRNJI","X-Authority-Analysis":"v=2.4 cv=VN/tWdPX c=1 sm=1 tr=0 ts=69d99934 cx=c_pps\n a=Uww141gWH0fZj/3QKPojxA==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17\n a=Y3tniwRYLMhsA3a_:21 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10\n a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22\n a=EUspDBNiAAAA:8 a=CpOf1x9CzB3aoCErBU0A:9 a=PxkB5W3o20Ba91AHUih5:22","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDExMDAwMyBTYWx0ZWRfX5sYf8kYKO/Yo\n /id6N7IV9P2gehWOv/42d9zJ5s//9OC/RsZV3WBH2Cc058UUWqjO4oCFY0yn+8ELIi7upzbar1H\n AkRlpPjmxWSliMaF7+iu11Lycdc5+DkEO28gnVaF8s7bT4hJHUUHS3X8e25i9XsDLA6E+QXKI+o\n i6DJv+s2JX5zC6osgIHimk4qvyd7u2tIkjD5gZubgylSEnR44PSPVO7Pkw1UBqlBkLg9IQkJjKg\n KcaUtKdPElUPCyFWr407ChRAKUCw1Zb4hoVojfryR01g2arK1fBqtVwHfYMjECZ+U2/09QpCohB\n qC0P5RMyur2dx2cCfN1YcKz79ULdIL+661PKCvd18ZipW0BOu+iYc2M4fxR5387FHGmyxI2NgKh\n 8FNw3vBfrj5kO+5jtINbPrWjKumNGYABkjft8i2HLKYiZX5yn1EQnl44jp2lbZoGJ209CnfyS6J\n LjOgWEMoZLa99sMR6ng==","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-10_07,2026-04-09_02,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n malwarescore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015\n impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604010000 definitions=main-2604110003","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":"Currently, cselim requires the middle_bb to have only a single statement. This\npatch relaxes this restriction if the following pattern is found and also when\nit is safe to do the optimization.\n\nSPLIT_BB:\n  ...\n  STORE = X\n  if (cond) goto MIDDLE_BB; else goto JOIN_BB (edge E1)\nMIDDLE_BB:\n  ...\n  STORE = Y;\n  ...\n  fallthrough (edge E0)\nJOIN_BB:\n  some more\n\nBootstrapped and tested on x86_64-linux-gnu and aarch64-linux-gnu.\n\n\tPR tree-optimization/124405\n\ngcc/ChangeLog:\n\n\t* tree-ssa-phiopt.cc (trailing_store_in_bb): Allow vphi to be NULL to\n\tsupport more general scenarios.\n\t(cselim_candidate): New.\n\t(cond_store_replacement): Add split_bb argument and call\n\tcselim_candidate instead of last_and_only_stmt.\n\t(pass_cselim::execute): Update call to cond_store_replacement.\n\ngcc/testsuite/ChangeLog:\n\n\t* gcc.dg/tree-ssa/pr124405.c: New test.\n\nSigned-off-by: Pengxuan Zheng <pengxuan.zheng@oss.qualcomm.com>\n---\n gcc/testsuite/gcc.dg/tree-ssa/pr124405.c |  12 ++\n gcc/tree-ssa-phiopt.cc                   | 151 +++++++++++++++++------\n 2 files changed, 124 insertions(+), 39 deletions(-)\n create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr124405.c","diff":"diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124405.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124405.c\nnew file mode 100644\nindex 00000000000..9ba230d2b56\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr124405.c\n@@ -0,0 +1,12 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O1 -fdump-tree-cselim-details\" } */\n+\n+void\n+f (int *a, int b)\n+{\n+  *a &= ~3;\n+  if (b)\n+    *a |= 1;\n+}\n+\n+/* { dg-final { scan-tree-dump-times \"Conditional store replacement happened\" 1 \"cselim\"} } */\ndiff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc\nindex 0bf7e58b8f0..1db20ce53e8 100644\n--- a/gcc/tree-ssa-phiopt.cc\n+++ b/gcc/tree-ssa-phiopt.cc\n@@ -2980,6 +2980,113 @@ get_non_trapping (void)\n   return nontrap;\n }\n \n+/* Return the last store in BB with VDEF or NULL if there are loads following\n+   the store.  VPHI if non-NULL is where the only use of the vdef should be.  If\n+   VPHI is NULL, return NULL if there is any load or store following the store.\n+   If ONLYONESTORE is true, then the store is the only store in the BB.  */\n+\n+static gimple *\n+trailing_store_in_bb (basic_block bb, tree vdef, gphi *vphi, bool onlyonestore)\n+{\n+  if (SSA_NAME_IS_DEFAULT_DEF (vdef))\n+    return NULL;\n+  gimple *store = SSA_NAME_DEF_STMT (vdef);\n+  if (gimple_bb (store) != bb\n+      || gimple_code (store) == GIMPLE_PHI)\n+    return NULL;\n+\n+  /* Verify there is no other store in this BB if requested.  */\n+  if (onlyonestore\n+      && !SSA_NAME_IS_DEFAULT_DEF (gimple_vuse (store))\n+      && gimple_bb (SSA_NAME_DEF_STMT (gimple_vuse (store))) == bb\n+      && gimple_code (SSA_NAME_DEF_STMT (gimple_vuse (store))) != GIMPLE_PHI)\n+    return NULL;\n+\n+  if (vphi)\n+    {\n+      /* Verify the vdef of the store should only be used by VPHI.  */\n+      use_operand_p use_p;\n+      gimple *use_stmt;\n+      if (!single_imm_use (gimple_vdef (store), &use_p, &use_stmt))\n+\treturn NULL;\n+      if (use_stmt != vphi)\n+\treturn NULL;\n+    }\n+  else\n+    {\n+      /* Verify there is no load or store after the store.  */\n+      use_operand_p use_p;\n+      imm_use_iterator imm_iter;\n+      FOR_EACH_IMM_USE_FAST (use_p, imm_iter, gimple_vdef (store))\n+\tif (USE_STMT (use_p) != store && gimple_bb (USE_STMT (use_p)) == bb)\n+\t  return NULL;\n+    }\n+\n+  return store;\n+}\n+\n+/* Return the candidate store for cselim.  If there is only a single statement\n+   in MIDDLE_BB, return that statement.  Otherwise, try to find the following\n+   pattern and return the only store in MIDDLE_BB.\n+\n+   SPLIT_BB:\n+     ...\n+     STORE = X\n+     if (cond) goto MIDDLE_BB; else goto JOIN_BB (edge E1)\n+   MIDDLE_BB:\n+     ...\n+     STORE = Y;\n+     ...\n+     fallthrough (edge E0)\n+   JOIN_BB:\n+     some more\n+*/\n+\n+static gimple *\n+cselim_candidate (basic_block split_bb, basic_block middle_bb,\n+\t\t  basic_block join_bb, edge e0, edge e1)\n+{\n+  gimple *middle_assign = last_and_only_stmt (middle_bb);\n+  if (middle_assign)\n+    return middle_assign;\n+\n+  gphi *vphi = get_virtual_phi (join_bb);\n+  if (!vphi)\n+    return NULL;\n+\n+  tree middle_vdef = PHI_ARG_DEF_FROM_EDGE (vphi, e0);\n+  middle_assign = trailing_store_in_bb (middle_bb, middle_vdef, vphi, true);\n+\n+  if (!middle_assign || !gimple_assign_single_p (middle_assign)\n+      || gimple_has_volatile_ops (middle_assign)\n+      || stmt_references_abnormal_ssa_name (middle_assign))\n+    return NULL;\n+\n+  tree split_vdef = PHI_ARG_DEF_FROM_EDGE (vphi, e1);\n+  gimple *split_assign\n+      = trailing_store_in_bb (split_bb, split_vdef, NULL, true);\n+\n+  if (!split_assign || !gimple_assign_single_p (split_assign)\n+      || gimple_has_volatile_ops (split_assign)\n+      || stmt_references_abnormal_ssa_name (split_assign))\n+    return NULL;\n+\n+  if (gimple_vdef (split_assign) != gimple_vuse (middle_assign)\n+      || !operand_equal_p (gimple_assign_lhs (middle_assign),\n+\t\t\t   gimple_assign_lhs (split_assign), 0))\n+    return NULL;\n+\n+  /* The vdef of split_assign should only be used by middle_assign or vphi.  */\n+  use_operand_p use_p;\n+  imm_use_iterator imm_iter;\n+  FOR_EACH_IMM_USE_FAST (use_p, imm_iter, gimple_vdef (split_assign))\n+    if (USE_STMT (use_p) != middle_assign\n+\t&& USE_STMT (use_p) != vphi)\n+      return NULL;\n+\n+  return middle_assign;\n+}\n+\n /* Do the main work of conditional store replacement.  We already know\n    that the recognized pattern looks like so:\n \n@@ -2997,10 +3104,11 @@ get_non_trapping (void)\n    object) and that the store has a \"simple\" RHS.  */\n \n static bool\n-cond_store_replacement (basic_block middle_bb, basic_block join_bb,\n-\t\t\tedge e0, edge e1, hash_set<tree> *nontrap)\n+cond_store_replacement (basic_block split_bb, basic_block middle_bb,\n+\t\t\tbasic_block join_bb, edge e0, edge e1,\n+\t\t\thash_set<tree> *nontrap)\n {\n-  gimple *assign = last_and_only_stmt (middle_bb);\n+  gimple *assign = cselim_candidate (split_bb, middle_bb, join_bb, e0, e1);\n   tree lhs, rhs, name, name2;\n   gphi *newphi;\n   gassign *new_stmt;\n@@ -3254,41 +3362,6 @@ cond_if_else_store_replacement_1 (basic_block then_bb, basic_block else_bb,\n   return true;\n }\n \n-/* Return the last store in BB with VDEF or NULL if there are\n-   loads following the store. VPHI is where the only use of the\n-   vdef should be.  If ONLYONESTORE is true, then the store is\n-   the only store in the BB.  */\n-\n-static gimple *\n-trailing_store_in_bb (basic_block bb, tree vdef, gphi *vphi, bool onlyonestore)\n-{\n-  if (SSA_NAME_IS_DEFAULT_DEF (vdef))\n-    return NULL;\n-  gimple *store = SSA_NAME_DEF_STMT (vdef);\n-  if (gimple_bb (store) != bb\n-      || gimple_code (store) == GIMPLE_PHI)\n-    return NULL;\n-\n-  /* Verify there is no other store in this BB if requested.  */\n-  if (onlyonestore\n-      && !SSA_NAME_IS_DEFAULT_DEF (gimple_vuse (store))\n-      && gimple_bb (SSA_NAME_DEF_STMT (gimple_vuse (store))) == bb\n-      && gimple_code (SSA_NAME_DEF_STMT (gimple_vuse (store))) != GIMPLE_PHI)\n-    return NULL;\n-\n-\n-  /* Verify there is no load or store after the store, the vdef of the store\n-     should only be used by the vphi joining the 2 bbs.  */\n-  use_operand_p use_p;\n-  gimple *use_stmt;\n-  if (!single_imm_use (gimple_vdef (store), &use_p, &use_stmt))\n-    return NULL;\n-  if (use_stmt != vphi)\n-    return NULL;\n-\n-  return store;\n-}\n-\n /* Limited Conditional store replacement.  We already know\n    that the recognized pattern looks like so:\n \n@@ -4259,7 +4332,7 @@ pass_cselim::execute (function *)\n \t optimization if the join block has more than two predecessors.  */\n       if (EDGE_COUNT (bb2->preds) > 2)\n \treturn;\n-      if (cond_store_replacement (bb1, bb2, e1, e2, nontrap))\n+      if (cond_store_replacement (bb, bb1, bb2, e1, e2, nontrap))\n \tcfgchanged = true;\n     };\n \n","prefixes":[]}