get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.1/patches/2231645/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2231645,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2231645/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260501020554.3194871-1-andrew.pinski@oss.qualcomm.com/",
    "project": {
        "id": 17,
        "url": "http://patchwork.ozlabs.org/api/1.1/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
    },
    "msgid": "<20260501020554.3194871-1-andrew.pinski@oss.qualcomm.com>",
    "date": "2026-05-01T02:05:54",
    "name": "[v2] phiprop: Allow for one store inbetween the load and the phi which is being used to insert [PR123120]",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "09e21e3a378d7380971bacf45b48042c3edc769a",
    "submitter": {
        "id": 91428,
        "url": "http://patchwork.ozlabs.org/api/1.1/people/91428/?format=api",
        "name": "Andrew Pinski",
        "email": "andrew.pinski@oss.qualcomm.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260501020554.3194871-1-andrew.pinski@oss.qualcomm.com/mbox/",
    "series": [
        {
            "id": 502414,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/502414/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=502414",
            "date": "2026-05-01T02:05:54",
            "name": "[v2] phiprop: Allow for one store inbetween the load and the phi which is being used to insert [PR123120]",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/502414/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2231645/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2231645/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=It6UCSqK;\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=hXpHGhM5;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.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=It6UCSqK;\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=hXpHGhM5",
            "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 [38.145.34.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 4g6DtQ1tCpz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 01 May 2026 12:06:38 +1000 (AEST)",
            "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 2F7B24374221\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  1 May 2026 02:06:36 +0000 (GMT)",
            "from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n [205.220.180.131])\n by sourceware.org (Postfix) with ESMTPS id 8F3484BA901C\n for <gcc-patches@gcc.gnu.org>; Fri,  1 May 2026 02:06:04 +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 63ULQLsd007763\n for <gcc-patches@gcc.gnu.org>; Fri, 1 May 2026 02:06:04 GMT",
            "from mail-pj1-f69.google.com (mail-pj1-f69.google.com\n [209.85.216.69])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dv54wbr5a-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Fri, 01 May 2026 02:06:03 +0000 (GMT)",
            "by mail-pj1-f69.google.com with SMTP id\n 98e67ed59e1d1-362d9dd9a49so1711480a91.0\n for <gcc-patches@gcc.gnu.org>; Thu, 30 Apr 2026 19:06:03 -0700 (PDT)",
            "from xeond2.wrightpinski.org ([98.97.38.95])\n by smtp.gmail.com with ESMTPSA id\n 41be03b00d2f7-c7ffbbbe8e9sm812379a12.10.2026.04.30.19.06.00\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 30 Apr 2026 19:06:00 -0700 (PDT)"
        ],
        "DKIM-Filter": [
            "OpenDKIM Filter v2.11.0 sourceware.org 2F7B24374221",
            "OpenDKIM Filter v2.11.0 sourceware.org 8F3484BA901C"
        ],
        "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 8F3484BA901C",
        "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 8F3484BA901C",
        "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777601164; cv=none;\n b=eqEVSbY40u3mhImnv0ua4NrueP/xfJc3XjXZlSO7zf8jr/OL1PADQAMWOil2w0o4t9yoztq4SVXCflLdK+7TVXm8wrcOwOfUCwC7jcQRIdfey+3aKpd1HmNhWjMVQZ0kCeeQu3S+ItVBYprlSKru6TMEEVSuqHiZuRw/hKr7caU=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777601164; c=relaxed/simple;\n bh=jbMeSBh8+UOovrQaijXvLv998w8jPp1k1W/dg3znSgA=;\n h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID:\n MIME-Version;\n b=sk8b/BlxRpkledsEk+tazfc4t2pQUzI06R6cwMy6U2XnUWCY/JLXev57rniU58YE59tb7i8HqDmj1Iu4BvWgDOg9RCGOxq0FE9KNNZjUuKuh8RsTBNhY52Cox/01cVwSJuMw15XTWjd1eLGVeIuzNvHUEgm0zAuY9hQoP6v6kOc=",
        "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=WkbA2lFJUf/ptsNr0V0tg+B9thZ33VLHRFD\n U8jI4aUA=; b=It6UCSqKIT9bY8zTg4EfR5VqTcNNdvstaEC/i7mAhEC/G0SdGdx\n s7/sQrXJdQIuZKWcBUNz9O57zmAvpfwlVhZ+67KkCXkMDYKvBumNy7lN2mmMmWgX\n DW18A4QJVJJc1VDGwBtaEGld4TUfpKVvxT0HXfsa9FDZh//2dJJ8IjDNQX6v4cH1\n LSWYj4VG/7U/NUeFdSUiW2/jsq4ZKPpGJ4WZ7FuydCNKcxYgt0aMwYRBsijCewPG\n rJvdumPjR/xc08pOkijdCbbfVeKmlhaHAHzsGZ6njsdWa3mRNXBlJXA/cVDBjc79\n I+MumknBahr88esFymQKCwJoBpojWdrz8hg==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1777601162; x=1778205962; 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=WkbA2lFJUf/ptsNr0V0tg+B9thZ33VLHRFDU8jI4aUA=;\n b=hXpHGhM5yDLysMi0Gs21yxW7nZzHLeg+3059vm8OoGgSk4h4DibyGMpPo/LijByWxt\n EIQrtOYQMI9FSZwbUheVY8mkaAZQluINNoSO2+99r0eK0v8j9hEFEFcg58X44CtbGxqD\n CMSh/Cl00qpBxFaOhNLzCD3DXNVQXeTJL58cmy2T8fTEte9GLFEnm3blyZc95jHpAH87\n Sp2DzzGMNn3fDCGe+vEkl5C593cqtv4SqjSPRsTSWtEWOUXXUjB6pcIxeWxtX4evhz8q\n i6VwNyAA1LGlMDHknKtTh1SWoec09gaATkGQQi2FhSpobZHD1JHNVJYa8jKntcQmn6vp\n ueLQ=="
        ],
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777601162; x=1778205962;\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=WkbA2lFJUf/ptsNr0V0tg+B9thZ33VLHRFDU8jI4aUA=;\n b=DQz3t9l4B9L/v5a9Z1E07GXrq4b9C7kThmggipBUIdpFk0WPhMaVLyY0OLhjCjd2E0\n 365NdEggoMmhsPdlbbNPiszyzmHuI32VEZFLP9RAy1i7vLvm2JUrqvVZXueGI3hf/dUu\n wF3XHOkWppUmSyYq6ZFpYtQ8RMxFzT65b788owcTyRajYqE/sM5AZdxqyO0UO2EBltTw\n loY/mmbA8DpWe5ywqaUfW1QXzvONKDDbOutzziA6rDi9RqtQMSyAWr90bzyAifFn/2bd\n NKCU+PtzdQaZxmOBuolyjAkQVBewTVvPmWdmaONnMN5JBvJGtVUfdi5maJ/ylXes3A1+\n aeNQ==",
        "X-Gm-Message-State": "AOJu0YwyIvJ+wy6rebgDFX3Zjg3/SiVEAEyDQmvB6WYxgfsSZRVsLU8K\n DOf/Z3eoYnBwzCilYG8wkRoNW1h7Fy3iPAYIvi/udNsVbu9ls2s1AU095bEQvw0W8itrhnSnHMg\n OiwS691cyoyJTL53zRV+TA5B3/WfiTM0wzXRQ4wW9XybP+vwOlcmOt5DojTRdRsluLubR",
        "X-Gm-Gg": "AeBDieuz3Y/sgaXkYb7ENolPts9mswtwYKG9OR1vXjrx5VIeX1nz1OlZxoT6CfnxO3w\n gJgNFz0xKV9DBDnMqrEghPfO2H0LqRjIqiKsstuRGtTelBkL2LyMtD4X3KR8tbmsXbjUChWcEeJ\n lw3mEx5UeDc1cWAFW8Iv6Bi9WmJ5Qpiv0e4Nz3YmcNH0izXpwe10xXyZZoMRjkoW+h5QbEICy0o\n bfskTjAHAcVLPA9eQ2auJ3V73pyiPuYqKLI6tcKAgKX7GIXe6Ty2/+6Mi6O5IgriqNJexE3VtSO\n mkljhbiMhDCkP9L27NfK1uR2BnoCpwfST3CPf5Pkn7ekq6sjXkHDoNVS7p09pHHQe1OZsvDLFmT\n Pr6yHxa6CAD3ntm3HE1y6+iKji691Axzs8s8xAaJe5mMWMjKwHFT3DMAk5Q==",
        "X-Received": [
            "by 2002:a17:90b:590d:b0:35d:90c4:59f3 with SMTP id\n 98e67ed59e1d1-364ef507fc7mr1130111a91.13.1777601162157;\n Thu, 30 Apr 2026 19:06:02 -0700 (PDT)",
            "by 2002:a17:90b:590d:b0:35d:90c4:59f3 with SMTP id\n 98e67ed59e1d1-364ef507fc7mr1130055a91.13.1777601161278;\n Thu, 30 Apr 2026 19:06:01 -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": "[PATCH v2] phiprop: Allow for one store inbetween the load and the\n phi which is being used to insert [PR123120]",
        "Date": "Thu, 30 Apr 2026 19:05:54 -0700",
        "Message-ID": "<20260501020554.3194871-1-andrew.pinski@oss.qualcomm.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-Proofpoint-GUID": "odAF9SA3IHrsv_bDHhvssN1LPvm9jXNJ",
        "X-Authority-Analysis": "v=2.4 cv=Rrf16imK c=1 sm=1 tr=0 ts=69f40a8b cx=c_pps\n a=vVfyC5vLCtgYJKYeQD43oA==:117 a=zSc8QJ3clla4Uiv8JlCtoQ==:17\n a=IvqslEMCfeOTk3xp:21 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10\n a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22\n a=EUspDBNiAAAA:8 a=kApbupQWTbeeXeoJebsA:9 a=rl5im9kqc5Lf4LNbBjHf:22",
        "X-Proofpoint-ORIG-GUID": "odAF9SA3IHrsv_bDHhvssN1LPvm9jXNJ",
        "X-Proofpoint-Spam-Details-Enc": "AW1haW4tMjYwNTAxMDAxOCBTYWx0ZWRfX04LIutjoOfXV\n msG0jqNwNFtlERI4BYFW/2EwVvpFfVJ8JSvszw2u4UpMoXD7uyB7hPgLJjxzS9a9JdV/p5f8G9c\n AW0HVZ5APurhsdXuhB9RXXILMkJmHBzTC8x6/m2jW19Hn5YSzf3U8/90+6K4qdeyGBXR1u4EyXo\n t0HBxswsKTGjgSkVi9Ls4ufpxT1aEsM6B8m7fEoYd/R11MDK0yqvK/DrR1qfHuMj2dlX9Px825a\n +ochiaaqPWvu/BsVmYo8Zc91WmfNOe4ceshw6ti3OZXI+c39xK7vLrJa4vmEN8uS5NLf1VewPoi\n sLJHk8ZdIug6yEnrs3SLwA+YeW00k9nd8VadGxTqjQEYuCilL3ETmprMrGtvA6jOwCHosBrQZWL\n 9Hn/Y5N4AOPRez1+poMf7xdIH2m92BQBGIckZvZG4oOuke8QagpWPLYbcg5Xapip0ox0Ey2jJKE\n i4xCX/06xhZnHw9DrFg==",
        "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-30_07,2026-04-30_02,2025-10-01_01",
        "X-Proofpoint-Spam-Details": "rule=outbound_notspam policy=outbound score=0\n phishscore=0 spamscore=0 suspectscore=0 priorityscore=1501 clxscore=1015\n impostorscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 bulkscore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605010018",
        "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": "So phiprop has one disadvantage is that if there is store between the\nphi with the addresses and the new load, phiprop will no do anything.\nThis means for some C++ code where you have a min of a max (or the opposite),\ndepending on the argument order of evaluation phiprop might do\nthe transformation or it might not (see tree-ssa/phiprop-3.C for examples).\nSo we need to allow skipping of one store inbetween the load and\nwhere the phi is located.\n\nAggregates include a store when doing phiprop so we need to check\nif there are also loads between the original store/load and the\nstore we are skipping. This can be added afterwards but I didn't\nsee aggregate case happening enough to make a big dent. I added\ntestcases (phiprop-{10,11}.c) to make sure cases where the load\nwould make a different shows up though.\n\nchanges since v1:\n* v2: rewrite can_handle_load to avoid duplicated skipping store code.\n\n\tPR tree-optimization/123120\n\tPR tree-optimization/116823\ngcc/ChangeLog:\n\n\t* tree-ssa-phiprop.cc (phiprop_insert_phi): Add other_vuse\n\targument, use it instead of the vuse on the use_stmt.\n\t(can_handle_load): Add aggregate argument. Also return the vuse\n\tof the load/store when the insert is allowed.\n\tSkipping over one non-modifying store for !aggregate.\n\t(propagate_with_phi): Update call to can_handle_load\n\tand phiprop_insert_phi.\n\ngcc/testsuite/ChangeLog:\n\n\t* gcc.dg/tree-ssa/phiprop-8.c: New test.\n\t* gcc.dg/tree-ssa/phiprop-9.c: New test.\n\t* gcc.dg/tree-ssa/phiprop-10.c: New test.\n\t* gcc.dg/tree-ssa/phiprop-11.c: New test.\n\t* gcc.dg/tree-ssa/phiprop-12.c: New test.\n\t* g++.dg/tree-ssa/phiprop-3.C: New test.\n\nSigned-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>\n---\n gcc/testsuite/g++.dg/tree-ssa/phiprop-3.C  |  23 +++++\n gcc/testsuite/gcc.dg/tree-ssa/phiprop-10.c |  30 ++++++\n gcc/testsuite/gcc.dg/tree-ssa/phiprop-11.c |  30 ++++++\n gcc/testsuite/gcc.dg/tree-ssa/phiprop-12.c |  30 ++++++\n gcc/testsuite/gcc.dg/tree-ssa/phiprop-8.c  |  27 +++++\n gcc/testsuite/gcc.dg/tree-ssa/phiprop-9.c  |  24 +++++\n gcc/tree-ssa-phiprop.cc                    | 109 ++++++++++++++++-----\n 7 files changed, 251 insertions(+), 22 deletions(-)\n create mode 100644 gcc/testsuite/g++.dg/tree-ssa/phiprop-3.C\n create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phiprop-10.c\n create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phiprop-11.c\n create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phiprop-12.c\n create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phiprop-8.c\n create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phiprop-9.c",
    "diff": "diff --git a/gcc/testsuite/g++.dg/tree-ssa/phiprop-3.C b/gcc/testsuite/g++.dg/tree-ssa/phiprop-3.C\nnew file mode 100644\nindex 00000000000..86ecb02b81b\n--- /dev/null\n+++ b/gcc/testsuite/g++.dg/tree-ssa/phiprop-3.C\n@@ -0,0 +1,23 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O1 -fdump-tree-phiprop1-details -fdump-tree-release_ssa\" } */\n+\n+/* PR tree-optimization/123120 */\n+/* The order of min/max arguments should not cause any issues with phiprop,\n+   the stores to the temps should not interfere with the loads from the temp.  */\n+\n+#include <algorithm>\n+\n+long f0(short c, short d, long long a)\n+{\n+   return std::max(std::min((long long)3, a), (long long)d);\n+}\n+\n+long f1(short c, short d, long long a)\n+{\n+   return std::max((long long)d, std::min((long long)3, a));\n+}\n+\n+/* { dg-final { scan-tree-dump-times \"Inserting PHI for result of load\" 4 \"phiprop1\"} } */\n+/* { dg-final { scan-tree-dump-times \"MIN_EXPR\" 2 \"release_ssa\"} } */\n+/* { dg-final { scan-tree-dump-times \"MAX_EXPR\" 2 \"release_ssa\"} } */\n+\ndiff --git a/gcc/testsuite/gcc.dg/tree-ssa/phiprop-10.c b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-10.c\nnew file mode 100644\nindex 00000000000..b630148faa5\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-10.c\n@@ -0,0 +1,30 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O2 -fno-tree-sra -fdump-tree-phiprop-details\" } */\n+/* PR tree-optimization/123120 */\n+/* Make sure the store to *e conflicts with the store to *d */\n+\n+\n+struct s1\n+{\n+  int a;\n+};\n+\n+void f(int *);\n+\n+void g(struct s1 i, struct s1 *d, struct s1 *e)\n+{\n+  const struct s1 t = {10};\n+  const struct s1 *a;\n+  struct s1 t1 = {2};\n+  if (t.a < i.a)\n+    a = &t;\n+  else\n+    a = &i;\n+  *e = t1;\n+  t1 = *a;\n+  *d = t1;\n+}\n+\n+/* { dg-final { scan-tree-dump-not \"Inserting PHI for result of load\" \"phiprop1\"} } */\n+/* { dg-final { scan-tree-dump-not \"Inserting PHI for result of load\" \"phiprop2\"} } */\n+\ndiff --git a/gcc/testsuite/gcc.dg/tree-ssa/phiprop-11.c b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-11.c\nnew file mode 100644\nindex 00000000000..6f078d175ef\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-11.c\n@@ -0,0 +1,30 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O2 -fno-tree-sra -fdump-tree-phiprop-details\" } */\n+/* PR tree-optimization/123120 */\n+/* Make sure the load *d conflicts with the store to *d so that phiprop\n+   does not move the store into conditionals. */\n+\n+struct s1\n+{\n+  int a;\n+};\n+\n+void f(int *);\n+\n+int g(struct s1 i, struct s1 *d, struct s1 *e)\n+{\n+  const struct s1 t = {10};\n+  const struct s1 *a;\n+  struct s1 t1 = {2};\n+  if (t.a < i.a)\n+    a = &t;\n+  else\n+    a = &i;\n+  t1 = *d;\n+  *d = *a;\n+  return t1.a;\n+}\n+\n+/* { dg-final { scan-tree-dump-not \"Inserting PHI for result of load\" \"phiprop1\"} } */\n+/* { dg-final { scan-tree-dump-not \"Inserting PHI for result of load\" \"phiprop2\"} } */\n+\ndiff --git a/gcc/testsuite/gcc.dg/tree-ssa/phiprop-12.c b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-12.c\nnew file mode 100644\nindex 00000000000..4cc2e5b8cd0\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-12.c\n@@ -0,0 +1,30 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O2 -fdump-tree-phiprop-details\" } */\n+/* PR tree-optimization/123120 */\n+/* Make sure the load *d conflicts with the store to *d so that phiprop\n+   does not move the store into conditionals. */\n+\n+struct s1\n+{\n+  int a;\n+};\n+\n+void f(int *);\n+\n+int g(struct s1 i, struct s1 *d, struct s1 *e)\n+{\n+  const struct s1 t = {10};\n+  const struct s1 *a;\n+  struct s1 t1 = {2};\n+  if (t.a < i.a)\n+    a = &t;\n+  else\n+    a = &i;\n+  int t2 = d->a;\n+  *d = *a;\n+  return t2;\n+}\n+\n+/* { dg-final { scan-tree-dump-not \"Inserting PHI for result of load\" \"phiprop1\"} } */\n+/* { dg-final { scan-tree-dump-not \"Inserting PHI for result of load\" \"phiprop2\"} } */\n+\ndiff --git a/gcc/testsuite/gcc.dg/tree-ssa/phiprop-8.c b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-8.c\nnew file mode 100644\nindex 00000000000..546031e63d7\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-8.c\n@@ -0,0 +1,27 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O1 -fdump-tree-phiprop1-details -fdump-tree-release_ssa\" } */\n+\n+/* PR tree-optimization/116823 */\n+/* The clobber on b should not get in the way of phiprop here. */\n+/* We should have MIN_EXPR early on. */\n+\n+void f(int *);\n+\n+int g(int i)\n+{\n+  const int t = 10;\n+  const int *a;\n+  {\n+    int b;\n+    f(&b);\n+    if (t < i)\n+      a = &t;\n+    else\n+      a = &i;\n+  }\n+  return *a;\n+}\n+\n+/* { dg-final { scan-tree-dump-times \"Inserting PHI for result of load\" 1 \"phiprop1\"} } */\n+/* { dg-final { scan-tree-dump-times \"MIN_EXPR\" 1 \"release_ssa\"} } */\n+\ndiff --git a/gcc/testsuite/gcc.dg/tree-ssa/phiprop-9.c b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-9.c\nnew file mode 100644\nindex 00000000000..bbd91eda95d\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-9.c\n@@ -0,0 +1,24 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O1 -fdump-tree-phiprop1-details -fdump-tree-release_ssa\" } */\n+\n+/* PR tree-optimization/123120 */\n+/* The store to *d should not get in the way of phiprop here. */\n+/* We should have MIN_EXPR early on. */\n+\n+void f(int *);\n+\n+int g(int i, int *d)\n+{\n+  const int t = 10;\n+  const int *a;\n+  if (t < i)\n+    a = &t;\n+  else\n+    a = &i;\n+  *d = 1;\n+  return *a;\n+}\n+\n+/* { dg-final { scan-tree-dump-times \"Inserting PHI for result of load\" 1 \"phiprop1\"} } */\n+/* { dg-final { scan-tree-dump-times \"MIN_EXPR\" 1 \"release_ssa\"} } */\n+\ndiff --git a/gcc/tree-ssa-phiprop.cc b/gcc/tree-ssa-phiprop.cc\nindex b7ce7b4a184..5985beae26a 100644\n--- a/gcc/tree-ssa-phiprop.cc\n+++ b/gcc/tree-ssa-phiprop.cc\n@@ -101,12 +101,14 @@ struct phiprop_d\n };\n \n /* Insert a new phi node for the dereference of PHI at basic_block\n-   BB with the virtual operands from USE_STMT.  */\n+   BB with the virtual operands from USE_STMT. The vuse for\n+   the load will be set to OTHER_VUSE unless there is virtual op\n+   phi for BB.  */\n \n static tree\n phiprop_insert_phi (basic_block bb, gphi *phi, gimple *use_stmt,\n \t\t    struct phiprop_d *phivn, size_t n,\n-\t\t    bitmap dce_ssa_names)\n+\t\t    bitmap dce_ssa_names, tree other_vuse)\n {\n   tree res;\n   gphi *new_phi = NULL;\n@@ -176,7 +178,7 @@ phiprop_insert_phi (basic_block bb, gphi *phi, gimple *use_stmt,\n \t      if (vphi)\n \t\tvuse = PHI_ARG_DEF_FROM_EDGE (vphi, e);\n \t      else\n-\t\tvuse = gimple_vuse (use_stmt);\n+\t\tvuse = other_vuse;\n \t    }\n \t  else\n \t    /* For the aggregate copy case updating virtual operands\n@@ -243,26 +245,85 @@ chk_uses (tree, tree *idx, void *data)\n    incoming VUSE (up_vuse).  If neither is present\n    make sure the def stmt of the virtual use is in a\n    different basic block dominating BB.  When the def\n-   is an edge-inserted one we know it dominates us.  */\n-static bool\n-can_handle_load (gimple *load_stmt, basic_block bb,\n-\t\t gphi *vphi, tree up_vuse)\n+   is an edge-inserted one we know it dominates us.\n+   Returns the vuse to use for the inserting.  NULL_TREE\n+   is returned when we can't do the insert.  */\n+\n+static tree\n+can_handle_load (gimple *load_stmt,\n+\t\t basic_block bb,\n+\t\t gphi *vphi, tree up_vuse, bool aggregate)\n {\n   tree vuse = gimple_vuse (load_stmt);\n-  if (vphi)\n-    return vuse == gimple_phi_result (vphi);\n-  if (up_vuse)\n-    return vuse == up_vuse;\n-  gimple *def_stmt = SSA_NAME_DEF_STMT (vuse);\n   /* If the load does not have a store beforehand,\n      then we can do the load in conditional. */\n   if (SSA_NAME_IS_DEFAULT_DEF (vuse))\n-    return true;\n-  if (gimple_bb (def_stmt) != bb\n+    {\n+      /* For loads that have no stores before, there should be no\n+\t vphi.  */\n+      gcc_checking_assert (!vphi);\n+      /* The common vuse is the same as the default or there is none. */\n+      gcc_checking_assert (!up_vuse || up_vuse == vuse);\n+      return vuse;\n+    }\n+\n+  /* If we have a vphi, then that needs to be end point.\n+     If we have a common incoming vuse, that needs to be the end point.  */\n+  tree expected_vuse = NULL_TREE;\n+  if (vphi)\n+    expected_vuse = gimple_phi_result (vphi);\n+  else if (up_vuse)\n+    expected_vuse = up_vuse;\n+\n+  /* If the vuse on the load is the same as the expected vuse,\n+     there are no stores inbetween.  */\n+  if (vuse == expected_vuse)\n+    return vuse;\n+  /* Try to see if the store does not effect the load.  */\n+  gimple *other_store = SSA_NAME_DEF_STMT (vuse);\n+  /* Only handling the case where the store is in the same\n+     bb as the phi.  */\n+  if (gimple_bb (other_store) == bb)\n+    {\n+      /* For aggregates, skipping the store is too\n+\t hard to handle as you need to check for loads\n+\t and it is not worth the extra checks. */\n+      if (aggregate)\n+\treturn NULL_TREE;\n+      tree src = gimple_assign_rhs1 (load_stmt);\n+      ao_ref read;\n+      ao_ref_init (&read, src);\n+      if (stmt_may_clobber_ref_p_1 (other_store, &read, false))\n+\treturn NULL_TREE;\n+      vuse = gimple_vuse (other_store);\n+      /* If that skipped store was the first store in program,\n+\t then we can do the load conditional.  */\n+      if (SSA_NAME_IS_DEFAULT_DEF (vuse))\n+\t{\n+\t  /* For loads that have no stores before, there should be no\n+\t     vphi.  */\n+\t  gcc_checking_assert (!vphi);\n+\t  /* The common vuse is the same as the default or there is none. */\n+\t  gcc_checking_assert (!up_vuse || up_vuse == vuse);\n+\t  return vuse;\n+\t}\n+      other_store = SSA_NAME_DEF_STMT (vuse);\n+      /* If the new vuse (after skipping) is the same as expected\n+\t then that is the vuse to return.  */\n+      if (vuse == expected_vuse)\n+\treturn vuse;\n+      if (gimple_bb (other_store) == bb)\n+\treturn NULL_TREE;\n+    }\n+\n+  /* If there was no an expected vuse then see if the vuse dominates the phi of\n+      the address.  */\n+  if (!expected_vuse\n       && dominated_by_p (CDI_DOMINATORS,\n-\t\t\t bb, gimple_bb (def_stmt)))\n-    return true;\n-  return false;\n+\t\t\t bb, gimple_bb (other_store)))\n+    return vuse;\n+\n+  return NULL_TREE;\n }\n \n /* Propagate between the phi node arguments of PHI in BB and phi result\n@@ -385,13 +446,15 @@ propagate_with_phi (basic_block bb, gphi *vphi, gphi *phi,\n \t    && !gimple_has_volatile_ops (use_stmt)))\n \tcontinue;\n \n-      if (!can_handle_load (use_stmt, bb, vphi, up_vuse))\n-\tcontinue;\n-\n       bool aggregate = false;\n       if (!is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (use_stmt))))\n \taggregate = true;\n \n+      tree other_vuse;\n+      other_vuse = can_handle_load (use_stmt, bb, vphi, up_vuse, aggregate);\n+      if (!other_vuse)\n+\tcontinue;\n+\n       if ((canpossible_trap || aggregate)\n \t  && !dom_info_available_p (cfun, CDI_POST_DOMINATORS))\n \tcalculate_dominance_info (CDI_POST_DOMINATORS);\n@@ -459,7 +522,8 @@ propagate_with_phi (basic_block bb, gphi *vphi, gphi *phi,\n \t\tgoto next;\n \t    }\n \n-\t  phiprop_insert_phi (bb, phi, use_stmt, phivn, n, dce_ssa_names);\n+\t  phiprop_insert_phi (bb, phi, use_stmt, phivn, n,\n+\t\t\t      dce_ssa_names, other_vuse);\n \n \t  /* Remove old stmt. The phi and all of maybe its depedencies\n \t     will be removed later via simple_dce_from_worklist. */\n@@ -492,7 +556,8 @@ propagate_with_phi (basic_block bb, gphi *vphi, gphi *phi,\n       else\n \t{\n \t  tree vuse = gimple_vuse (use_stmt);\n-\t  res = phiprop_insert_phi (bb, phi, use_stmt, phivn, n, dce_ssa_names);\n+\t  res = phiprop_insert_phi (bb, phi, use_stmt, phivn, n,\n+\t\t\t\t    dce_ssa_names, other_vuse);\n \t  type = TREE_TYPE (res);\n \n \t  /* Remember the value we created for *ptr.  */\n",
    "prefixes": [
        "v2"
    ]
}