[{"id":3678910,"web_url":"http://patchwork.ozlabs.org/comment/3678910/","msgid":"<CALvbMcCCn_D3DBwnp7QvFrsBOwRKha0tjJ1TYjO_GtDzoaLO0w@mail.gmail.com>","list_archive_url":null,"date":"2026-04-17T23:45:02","subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","submitter":{"id":91428,"url":"http://patchwork.ozlabs.org/api/people/91428/","name":"Andrew Pinski","email":"andrew.pinski@oss.qualcomm.com"},"content":"On Fri, Apr 17, 2026 at 4:36 PM liuhongt <hongtao.liu@intel.com> wrote:\n>\n> DSE can forward-substitute a stored value into a load and then delete\n> the store as dead.  This leaves REG_EQUAL notes on other insns that\n> reference the same memory location stale, since the memory now holds\n> a different (older) value.\n>\n> When late-combine propagates a register source into such a stale\n> REG_EQUAL note, the note can end up with two identical MEM references\n> (e.g. (minus (mem[X]) (mem[X]))) that simplify_binary_operation folds\n> to zero.  IRA then promotes REG_EQUAL(0) to REG_EQUIV(0), and reload\n> eliminates the computation entirely, producing wrong code.\n>\n> Fix this by dropping REG_EQUAL/REG_EQUIV notes that contain any\n> non-readonly MEM before propagating into them.  Read-only MEMs (such\n> as constant pool references) are safe since their contents cannot\n> change.  REG_EQUAL notes are just optimization hints, so dropping\n> them is always safe.\n>\n>\n> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.\n> Ok for trunk?\n\nI am not sure this is the right approach reading the bug report. I\nthought it was mentioned this REG_EQUAL should never have been created\nin the first place.\nCan you see where the REG_EQUAL with the MEM was added in the first\nplace and try not to add it there?\nI don't see why there is a REG_EQUAL anyways there.\nPlus since we don't have a LLM policy in place I am not going to\nreview this patch otherwise.\n\nThanks,\nAndrew\n\n>\n> gcc/ChangeLog:\n>\n>         PR rtl-optimization/124894\n>         * rtl.h (contains_nonreadonly_mem_rtx_p): Declare.\n>         * rtlanal.cc (contains_nonreadonly_mem_rtx_p): New function.\n>         * late-combine.cc (insn_combination::substitute_note): Drop\n>         REG_EQUAL/REG_EQUIV notes that reference non-readonly MEM.\n>\n> gcc/testsuite/ChangeLog:\n>\n>         PR rtl-optimization/124894\n>         * gcc.dg/pr124894.c: New test.\n>\n> Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>\n> ---\n>  gcc/late-combine.cc             | 11 ++++++++++\n>  gcc/rtl.h                       |  1 +\n>  gcc/rtlanal.cc                  | 13 ++++++++++++\n>  gcc/testsuite/gcc.dg/pr124894.c | 36 +++++++++++++++++++++++++++++++++\n>  4 files changed, 61 insertions(+)\n>  create mode 100644 gcc/testsuite/gcc.dg/pr124894.c\n>\n> diff --git a/gcc/late-combine.cc b/gcc/late-combine.cc\n> index aeb3ba17615..069d6b21161 100644\n> --- a/gcc/late-combine.cc\n> +++ b/gcc/late-combine.cc\n> @@ -350,6 +350,17 @@ insn_combination::substitute_note (insn_info *use_insn, rtx note,\n>    if (REG_NOTE_KIND (note) == REG_EQUAL\n>        || REG_NOTE_KIND (note) == REG_EQUIV)\n>      {\n> +      // If the note references a MEM, drop it rather than propagating\n> +      // into it.  The MEM's value may have been changed by a store that\n> +      // was later deleted (e.g. by DSE), making the note stale.\n> +      // Propagating into such a note could produce incorrect\n> +      // simplifications (e.g. (minus (mem) (mem)) folded to zero when\n> +      // the two references actually correspond to different values).\n> +      // Read-only MEMs are safe, since their contents cannot change.\n> +      // Since the note is just a hint, it is always safe to drop it.\n> +      if (contains_nonreadonly_mem_rtx_p (XEXP (note, 0)))\n> +       return false;\n> +\n>        insn_propagation prop (use_insn->rtl (), m_dest, m_src);\n>        return (prop.apply_to_note (&XEXP (note, 0))\n>               && (can_propagate || prop.num_replacements == 0));\n> diff --git a/gcc/rtl.h b/gcc/rtl.h\n> index eebcc18a4f1..a5ccdadcfc2 100644\n> --- a/gcc/rtl.h\n> +++ b/gcc/rtl.h\n> @@ -3765,6 +3765,7 @@ extern rtx tablejump_casesi_pattern (const rtx_insn *insn);\n>  extern bool computed_jump_p (const rtx_insn *);\n>  extern bool tls_referenced_p (const_rtx);\n>  extern bool contains_mem_rtx_p (rtx x);\n> +extern bool contains_nonreadonly_mem_rtx_p (rtx x);\n>  extern bool register_asm_p (const_rtx);\n>\n>  /* Overload for refers_to_regno_p for checking a single register.  */\n> diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc\n> index 88561a54e5a..70c75a0dee3 100644\n> --- a/gcc/rtlanal.cc\n> +++ b/gcc/rtlanal.cc\n> @@ -710,6 +710,19 @@ contains_mem_rtx_p (rtx x)\n>    return false;\n>  }\n>\n> +/* Return true if X contains a MEM subrtx whose contents might change.  */\n> +\n> +bool\n> +contains_nonreadonly_mem_rtx_p (rtx x)\n> +{\n> +  subrtx_iterator::array_type array;\n> +  FOR_EACH_SUBRTX (iter, array, x, ALL)\n> +    if (MEM_P (*iter) && !MEM_READONLY_P (*iter))\n> +      return true;\n> +\n> +  return false;\n> +}\n> +\n>  /* Return true if X is an address that is known to not be zero.  */\n>\n>  bool\n> diff --git a/gcc/testsuite/gcc.dg/pr124894.c b/gcc/testsuite/gcc.dg/pr124894.c\n> new file mode 100644\n> index 00000000000..f906169c699\n> --- /dev/null\n> +++ b/gcc/testsuite/gcc.dg/pr124894.c\n> @@ -0,0 +1,36 @@\n> +/* { dg-do run } */\n> +/* { dg-require-effective-target int128 } */\n> +/* { dg-require-effective-target lp64 } */\n> +/* { dg-options \"-O2 -fno-strict-aliasing\" } */\n> +\n> +/* PR rtl-optimization/124894 */\n> +/* DSE can delete a store after forward-substituting the stored value into\n> +   a load, leaving a stale MEM in a REG_EQUAL note.  Late-combine must not\n> +   propagate into such notes, as the resulting simplification (e.g.\n> +   (minus (mem) (mem)) -> 0) would be wrong.  */\n> +\n> +short s;\n> +__int128 z;\n> +long g;\n> +\n> +__attribute__((noipa)) long\n> +foo (short a)\n> +{\n> +  long t = 0;\n> +  char c = *(char *) __builtin_memset (&z, 2, 6);\n> +  __builtin_memset (&s, c, 2);\n> +  __builtin_memmove (&t, &g, 4);\n> +  long u = -t;\n> +  long v = *(long *) __builtin_memset (&t, a | 6, 8);\n> +  __int128 w = z % s;\n> +  long r = w + t + u + v;\n> +  return r;\n> +}\n> +\n> +int\n> +main ()\n> +{\n> +  long x = foo (0);\n> +  if (x != 0x0c0c0c0c0c0c0c0c)\n> +    __builtin_abort ();\n> +}\n> --\n> 2.34.1\n>","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=pnnG9VfZ;\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=b3LsYph2;\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=pnnG9VfZ;\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=b3LsYph2","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=pass smtp.remote-ip=205.220.168.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 4fyBMw4g9xz1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 09:45:47 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 785304B920AB\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 23:45:45 +0000 (GMT)","from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com\n [205.220.168.131])\n by sourceware.org (Postfix) with ESMTPS id A229C4B920AB\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 23:45:16 +0000 (GMT)","from pps.filterd (m0279865.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63HG49Nh2932811\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 23:45:15 GMT","from mail-dy1-f200.google.com (mail-dy1-f200.google.com\n [74.125.82.200])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dkhshanwt-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 23:45:15 +0000 (GMT)","by mail-dy1-f200.google.com with SMTP id\n 5a478bee46e88-2dd1c74508cso2429919eec.0\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 16:45:15 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 785304B920AB","OpenDKIM Filter v2.11.0 sourceware.org A229C4B920AB"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org A229C4B920AB","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org A229C4B920AB","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1776469516; cv=pass;\n b=wyqqTyKPrP4zjBnNgbW34JG6mRIsqgc/cTkbvgoNs3NSL6aaaVZWcqpgm5QBTsJN67AWgP8AzvI90oFFEu3FTmvKKA3ZpnM+RvlK3ti17E4VESTEnXWju7lmYsSKqPVO5zVHq0SxKVDWSCQWufbD7Mo4v+MOZGY6oXLbxSnPonY=","i=1; a=rsa-sha256; t=1776469515; cv=none;\n d=google.com; s=arc-20240605;\n b=INB5GiZRkn9c33plyml928spi9c3wOwBAcSiZdVcWYGPLEGNP19Q5YPxklkVmj23+V\n NMICShGLx5HsqdiAXJRyBo9Hr70GCOKyF9uOjlbwKkNWy9veTlW5t1D1rkFxS6H8qcFC\n NsymFf6vVkWbbkwQDDgs+Xd9GR5wRjP169rIo0j1zDlCCM0+K4lzlOBdO3xreFGcgnkx\n gI64TudAuMpXQbl1XBxJA2152I5O1HepqfCpDCKf4KtMtdgkpEVFqRsOE5QVmF5VZ8Tb\n C9TD7W+d306CNaO6wqkeOAYAhtEU4qEcRHP2U+m77Stt6XfFtm84lpzHZr0i8l9N8wly\n doMw=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776469516; c=relaxed/simple;\n bh=zPl7K4vcs5Q/7F21NkrH2guVlF4KHIe7YC/y3FlMmLY=;\n h=DKIM-Signature:DKIM-Signature:MIME-Version:From:Date:Message-ID:\n Subject:To;\n b=u1XT2mLJdnwFzAMWnbJO/xogERsnpDWs4J5MoeyY7hf2ceGBMf3yDj31hHyqshn0Vs+q040LoxI+VMZHwh5E4RGbjLHLOqf3AV9Th0EKGwwBSa6EMj3GTfEF3QqtjdA5mMzCWIEzSbS+CDBD3f9/7cYSdTS2aQ70/lrahuAHyZg=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:dkim-signature;\n bh=QCxmmSTBI7nXNPxSslYTXE52JV+tEIDsIp6VDCOP7T4=;\n fh=mcOGApQkSFNeTB11IhJAh97zncgwGdrCjCk6ifYIdEI=;\n b=aNVcw2NfSwsgG/gjvQ19ApvhS4FqQoMRZUtjPiGl9OeWAyDpPUNrrLmJ3vfcc9UHpc\n +GJ1uMSg5zRhB6MODBPbz7pBHk3TylB5nDY4sIqMRvY3rv6jAV28do2dTFAANNGfkWfO\n oxCRt8MYohM41koxLlf9fnBTFDFGTwmp3L/PaKQAZj9lbLmhKdfKpNW13yb9kr+mBWg5\n VMTN7JOlB30FV50RWwse9zFVfSCNm9x5egHzMnw79ZPS+Y4IyOas7XcW17gEyjJqjul0\n 4cPVHBxbjCtH8wW32pGNdq36Zl+tlhGzfsTT3FYEtsrkVL/coZKHfGpExrn3Vg2WsuH9\n fM/w==; darn=gcc.gnu.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:content-type:date:from:in-reply-to\n :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n QCxmmSTBI7nXNPxSslYTXE52JV+tEIDsIp6VDCOP7T4=; b=pnnG9VfZGZxfR5E7\n RgXkPNu7pheqSRAGABXwBuA5yiSK8os3HKRbcfpwLDY72Oth5vbgXPGjcfcherBh\n NhI99IOp43i5eOv4asIeF9qOulmpyPxiRdQB4lyUreKtL6S5JMgCdmyevv0FJ8Ir\n yd72vaAGhFEfj5F38yNKDKG78Ib1t70K+4zFr3knPy/eWyvUwlNDigSp2mrO11AY\n dVPYnygmlowSyWQ21Es8rtzHvllklMIG93RCRWU/xMbV+LEJEu4682O/Rd/auHuf\n z2H771efTiX3rqd00A8QhWutwx9xfK6ex37gtJKtiU/3WP7dq33955qNllC1zkjf\n c8egIw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1776469515; x=1777074315; darn=gcc.gnu.org;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:from:to:cc:subject:date\n :message-id:reply-to;\n bh=QCxmmSTBI7nXNPxSslYTXE52JV+tEIDsIp6VDCOP7T4=;\n b=b3LsYph2FDDnd85R8/52F+of2x4WY9P/EhSoG3L/gTKMgwE60ESnB64kkvQBw5Dlv5\n mgvwRxL5qRqA5pZN/mg8GtCFn+Olmfopw1SzjXL+xlSepHm/Qm/PFI/4KakFdyeDgjqs\n RtlQ4F5Y18WXdbzidczYFM2V44/Y5BwqWVbDPqik9WMQxyHm515RIhg+FngSaVe9ihS6\n Meip8wemCtQqz7g8/Sc9HxFM5n3fHrOTLsWy0JuI7JJunaCzEwu/PUSBYfi2vRGEnbw4\n rSUdSAfgNvIiMbxmP/k1qNPQlqVpshEFQoDhXMoTZQkNZOEzNnavZ8utQ/gITt9CdkH3\n t/JQ=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776469515; x=1777074315;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=QCxmmSTBI7nXNPxSslYTXE52JV+tEIDsIp6VDCOP7T4=;\n b=nAi3D7KRPrGPxsDL6INOSozyuVEc06rziewoj+aJu/yiQwNpf0VVsy6PkwIwXNp/Dh\n YijW1ShBKmf1/IC56oZ6Ku34gV2qCoKSF2Rgwzwj9AYCkAGTw93kJqrXuigqn+OyorQy\n CDXWevL9gL8bjSvJKo2q0znFPt9ux3BfqJ+9xRb/ETW1C0kRpMuyjcOu6R8+Np3nQbLv\n NPPIuqpN5HooJaJ3BvNztmghEI76cuELRB3bjvWnbEXNuhzwZG8LHPwLPv42nZ5JTu/f\n yaXgxXymoQp34P1Goj0YBll8zLT4jD7WmnXetSaOj7+STNBDXLaa8u6Ssv0PKFrlCCDG\n Q/oA==","X-Gm-Message-State":"AOJu0YxkQCGRY+IviW5q4Mv+3LOZNpkf5m8InF/8Jf6gaC+1axWs1j5p\n e0K6t2c//uNYt/RfR9yUI5OzbP+utAKFTf3wUaTVm0+UJ3WHl11w//03E2dHGipCilg8KY/NaJA\n VmVnARok4GoV4oLjLn1usH+7YCjstu2Wa3zs6m783PbhTPBmmYahnkhcehjFJAwDZelVO1Z3ql7\n dJase3WZmzCcftoaVdnekf6j5oCfT8nSVNygM=","X-Gm-Gg":"AeBDiesSOAVQ9NebjKTUKlrBnmYw8UxNqsgzbtgiHWVCJ8tYCWOo7NKo93OEWicbV0R\n q1hHyi5ErUs2fsh7rDdOV7iGVRCi4RMKSpYroUoFtW9wUVWCXoWxyJ4XAvEZjN4a/1amNl8C/uc\n fzQKd2EWD3beISVL7CMsr/P+hM7lKk5S+Dnq5l4ffeS+WQ44LfIq/Lsg/m7+ag3Kw0GZe19z99r\n avrMaWmtXe1Nhc=","X-Received":["by 2002:a05:7301:1007:b0:2d9:6373:ad11 with SMTP id\n 5a478bee46e88-2e47901499fmr3079627eec.28.1776469514533;\n Fri, 17 Apr 2026 16:45:14 -0700 (PDT)","by 2002:a05:7301:1007:b0:2d9:6373:ad11 with SMTP id\n 5a478bee46e88-2e47901499fmr3079610eec.28.1776469513910; Fri, 17 Apr 2026\n 16:45:13 -0700 (PDT)"],"MIME-Version":"1.0","References":"<20260417233535.524431-1-hongtao.liu@intel.com>","In-Reply-To":"<20260417233535.524431-1-hongtao.liu@intel.com>","From":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Date":"Fri, 17 Apr 2026 16:45:02 -0700","X-Gm-Features":"AQROBzDn85-zuc2lujrnwF4djnVjE743FSIy8SVrbPkzM2V_4Wx8DOgYLxJLtMs","Message-ID":"\n <CALvbMcCCn_D3DBwnp7QvFrsBOwRKha0tjJ1TYjO_GtDzoaLO0w@mail.gmail.com>","Subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","To":"liuhongt <hongtao.liu@intel.com>","Cc":"gcc-patches@gcc.gnu.org, rguenther@suse.de","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-Authority-Analysis":"v=2.4 cv=d6/FDxjE c=1 sm=1 tr=0 ts=69e2c60b cx=c_pps\n a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10\n a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22\n a=Um2Pa8k9VHT-vaBCBUpS:22 a=QyXUC8HyAAAA:8 a=6gl_cCoBAAAA:8\n a=E3d-7-v67uun8nbrmq0A:9 a=QEXdDO2ut3YA:10 a=6Ab_bkdmUrQuMsNx7PHu:22\n a=Bor9z-CvbNo2M6AZn8_k:22","X-Proofpoint-GUID":"jQclM58e9ojgASXP_x2E-JI3E_4czAMJ","X-Proofpoint-ORIG-GUID":"jQclM58e9ojgASXP_x2E-JI3E_4czAMJ","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDE3MDIzOCBTYWx0ZWRfX0oHVDrDfxH7F\n Djya5VYBTFrY0txqAo1aITw0dTxM4rUISoQ4THB3rV53gV9SPer7kAhWueQuD+bwN7B+CtRUHeh\n qy8TQ7tLhdk3f67k6CBOAvhekBX+orPYTqqladcK9886c2wYJ8q7BzxEr81Nyoe/QjKJX7vDQPp\n qlqXWVBsfO8/ujEQe+QYBdJRree56LX8x399BPvxHgGH9HcqefvI9/otNaOhkS4QlVA2mWrt+i1\n MDkzTNprgimrqRZ28xJSAA9ipUJwx5Ao/5iLVpaJD0ZS+4mlgpj3DwJcNinYH2tafQwxPc1Z0KR\n 6IVz2qLKKAKIDLCtg3EOhFnHG+9oKVQUAss8KOXRUDdJ12w6kQfghJqEyKr3EQdrFW/c1zOGfpC\n jss68Otbo9UDyiCpLlgvv2mEVUBKs+MTobtlOdU7ol7wwl7ZG+ZdP0jco+QEUXYV+KQZxEMgiOt\n vF9u2lHVb9k4QljnKFg==","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-17_03,2026-04-17_04,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n impostorscore=0 phishscore=0 bulkscore=0 priorityscore=1501 malwarescore=0\n lowpriorityscore=0 adultscore=0 clxscore=1015 suspectscore=0 spamscore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604170238","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"}},{"id":3678912,"web_url":"http://patchwork.ozlabs.org/comment/3678912/","msgid":"<CALvbMcCR1F4tVcmDeSRVo=5cU+sPJxPN_1w4XDBsB0JvF28DTw@mail.gmail.com>","list_archive_url":null,"date":"2026-04-17T23:56:04","subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","submitter":{"id":91428,"url":"http://patchwork.ozlabs.org/api/people/91428/","name":"Andrew Pinski","email":"andrew.pinski@oss.qualcomm.com"},"content":"On Fri, Apr 17, 2026 at 4:45 PM Andrew Pinski\n<andrew.pinski@oss.qualcomm.com> wrote:\n>\n> On Fri, Apr 17, 2026 at 4:36 PM liuhongt <hongtao.liu@intel.com> wrote:\n> >\n> > DSE can forward-substitute a stored value into a load and then delete\n> > the store as dead.  This leaves REG_EQUAL notes on other insns that\n> > reference the same memory location stale, since the memory now holds\n> > a different (older) value.\n> >\n> > When late-combine propagates a register source into such a stale\n> > REG_EQUAL note, the note can end up with two identical MEM references\n> > (e.g. (minus (mem[X]) (mem[X]))) that simplify_binary_operation folds\n> > to zero.  IRA then promotes REG_EQUAL(0) to REG_EQUIV(0), and reload\n> > eliminates the computation entirely, producing wrong code.\n> >\n> > Fix this by dropping REG_EQUAL/REG_EQUIV notes that contain any\n> > non-readonly MEM before propagating into them.  Read-only MEMs (such\n> > as constant pool references) are safe since their contents cannot\n> > change.  REG_EQUAL notes are just optimization hints, so dropping\n> > them is always safe.\n> >\n> >\n> > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.\n> > Ok for trunk?\n>\n> I am not sure this is the right approach reading the bug report. I\n> thought it was mentioned this REG_EQUAL should never have been created\n> in the first place.\n> Can you see where the REG_EQUAL with the MEM was added in the first\n> place and try not to add it there?\n> I don't see why there is a REG_EQUAL anyways there.\n> Plus since we don't have a LLM policy in place I am not going to\n> review this patch otherwise.\n\nAlso it is NOT the job of a different pass to fix up a problem from a\ndifferent pass. That is a very fragile approach.\n\n>\n> Thanks,\n> Andrew\n>\n> >\n> > gcc/ChangeLog:\n> >\n> >         PR rtl-optimization/124894\n> >         * rtl.h (contains_nonreadonly_mem_rtx_p): Declare.\n> >         * rtlanal.cc (contains_nonreadonly_mem_rtx_p): New function.\n> >         * late-combine.cc (insn_combination::substitute_note): Drop\n> >         REG_EQUAL/REG_EQUIV notes that reference non-readonly MEM.\n> >\n> > gcc/testsuite/ChangeLog:\n> >\n> >         PR rtl-optimization/124894\n> >         * gcc.dg/pr124894.c: New test.\n> >\n> > Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>\n> > ---\n> >  gcc/late-combine.cc             | 11 ++++++++++\n> >  gcc/rtl.h                       |  1 +\n> >  gcc/rtlanal.cc                  | 13 ++++++++++++\n> >  gcc/testsuite/gcc.dg/pr124894.c | 36 +++++++++++++++++++++++++++++++++\n> >  4 files changed, 61 insertions(+)\n> >  create mode 100644 gcc/testsuite/gcc.dg/pr124894.c\n> >\n> > diff --git a/gcc/late-combine.cc b/gcc/late-combine.cc\n> > index aeb3ba17615..069d6b21161 100644\n> > --- a/gcc/late-combine.cc\n> > +++ b/gcc/late-combine.cc\n> > @@ -350,6 +350,17 @@ insn_combination::substitute_note (insn_info *use_insn, rtx note,\n> >    if (REG_NOTE_KIND (note) == REG_EQUAL\n> >        || REG_NOTE_KIND (note) == REG_EQUIV)\n> >      {\n> > +      // If the note references a MEM, drop it rather than propagating\n> > +      // into it.  The MEM's value may have been changed by a store that\n> > +      // was later deleted (e.g. by DSE), making the note stale.\n> > +      // Propagating into such a note could produce incorrect\n> > +      // simplifications (e.g. (minus (mem) (mem)) folded to zero when\n> > +      // the two references actually correspond to different values).\n> > +      // Read-only MEMs are safe, since their contents cannot change.\n> > +      // Since the note is just a hint, it is always safe to drop it.\n> > +      if (contains_nonreadonly_mem_rtx_p (XEXP (note, 0)))\n> > +       return false;\n> > +\n> >        insn_propagation prop (use_insn->rtl (), m_dest, m_src);\n> >        return (prop.apply_to_note (&XEXP (note, 0))\n> >               && (can_propagate || prop.num_replacements == 0));\n> > diff --git a/gcc/rtl.h b/gcc/rtl.h\n> > index eebcc18a4f1..a5ccdadcfc2 100644\n> > --- a/gcc/rtl.h\n> > +++ b/gcc/rtl.h\n> > @@ -3765,6 +3765,7 @@ extern rtx tablejump_casesi_pattern (const rtx_insn *insn);\n> >  extern bool computed_jump_p (const rtx_insn *);\n> >  extern bool tls_referenced_p (const_rtx);\n> >  extern bool contains_mem_rtx_p (rtx x);\n> > +extern bool contains_nonreadonly_mem_rtx_p (rtx x);\n> >  extern bool register_asm_p (const_rtx);\n> >\n> >  /* Overload for refers_to_regno_p for checking a single register.  */\n> > diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc\n> > index 88561a54e5a..70c75a0dee3 100644\n> > --- a/gcc/rtlanal.cc\n> > +++ b/gcc/rtlanal.cc\n> > @@ -710,6 +710,19 @@ contains_mem_rtx_p (rtx x)\n> >    return false;\n> >  }\n> >\n> > +/* Return true if X contains a MEM subrtx whose contents might change.  */\n> > +\n> > +bool\n> > +contains_nonreadonly_mem_rtx_p (rtx x)\n> > +{\n> > +  subrtx_iterator::array_type array;\n> > +  FOR_EACH_SUBRTX (iter, array, x, ALL)\n> > +    if (MEM_P (*iter) && !MEM_READONLY_P (*iter))\n> > +      return true;\n> > +\n> > +  return false;\n> > +}\n> > +\n> >  /* Return true if X is an address that is known to not be zero.  */\n> >\n> >  bool\n> > diff --git a/gcc/testsuite/gcc.dg/pr124894.c b/gcc/testsuite/gcc.dg/pr124894.c\n> > new file mode 100644\n> > index 00000000000..f906169c699\n> > --- /dev/null\n> > +++ b/gcc/testsuite/gcc.dg/pr124894.c\n> > @@ -0,0 +1,36 @@\n> > +/* { dg-do run } */\n> > +/* { dg-require-effective-target int128 } */\n> > +/* { dg-require-effective-target lp64 } */\n> > +/* { dg-options \"-O2 -fno-strict-aliasing\" } */\n> > +\n> > +/* PR rtl-optimization/124894 */\n> > +/* DSE can delete a store after forward-substituting the stored value into\n> > +   a load, leaving a stale MEM in a REG_EQUAL note.  Late-combine must not\n> > +   propagate into such notes, as the resulting simplification (e.g.\n> > +   (minus (mem) (mem)) -> 0) would be wrong.  */\n> > +\n> > +short s;\n> > +__int128 z;\n> > +long g;\n> > +\n> > +__attribute__((noipa)) long\n> > +foo (short a)\n> > +{\n> > +  long t = 0;\n> > +  char c = *(char *) __builtin_memset (&z, 2, 6);\n> > +  __builtin_memset (&s, c, 2);\n> > +  __builtin_memmove (&t, &g, 4);\n> > +  long u = -t;\n> > +  long v = *(long *) __builtin_memset (&t, a | 6, 8);\n> > +  __int128 w = z % s;\n> > +  long r = w + t + u + v;\n> > +  return r;\n> > +}\n> > +\n> > +int\n> > +main ()\n> > +{\n> > +  long x = foo (0);\n> > +  if (x != 0x0c0c0c0c0c0c0c0c)\n> > +    __builtin_abort ();\n> > +}\n> > --\n> > 2.34.1\n> >","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=h69eE1N3;\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=M8mjC6YQ;\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=h69eE1N3;\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=M8mjC6YQ","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=pass smtp.remote-ip=205.220.168.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 4fyBd32gKYz1y1V\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 09:56:49 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id AEA184CD2021\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 23:56:47 +0000 (GMT)","from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com\n [205.220.168.131])\n by sourceware.org (Postfix) with ESMTPS id 9B4E94B920B4\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 23:56:19 +0000 (GMT)","from pps.filterd (m0279862.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63HG4Gmc4044456\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 23:56:18 GMT","from mail-dy1-f199.google.com (mail-dy1-f199.google.com\n [74.125.82.199])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dkqumh7ut-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 23:56:18 +0000 (GMT)","by mail-dy1-f199.google.com with SMTP id\n 5a478bee46e88-2d8a677cdfaso1484763eec.1\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 16:56:18 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org AEA184CD2021","OpenDKIM Filter v2.11.0 sourceware.org 9B4E94B920B4"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 9B4E94B920B4","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 9B4E94B920B4","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1776470179; cv=pass;\n b=s/Q9JvfqQphJ0VL74lRNEd6ZT5we11/SE8ez7emOq/J08fCBMeFaBD8RURVvHGzZxqttlQqrbqpHT0E+nmWid2+ZA91/8CaIniwkp+ajjjE0y/odMCy0la9hs+9WjiXf0ozbJzASldAu511MdLpXsiK4+DQVi28UHOxNdg3sKmk=","i=1; a=rsa-sha256; t=1776470178; cv=none;\n d=google.com; s=arc-20240605;\n b=MGGstwc/3blohbq+Lga3Jd14BkxGqtg5tL/9MQkqsVVeaaCZhjrY1ZbaVSZAliLulU\n TDNodg+rpGIa/SDZOTL6SB9d/7pmXZTEexqVvnREZgdhIaYglAnd+hViG91Rs5HfoZcS\n aoJgdmCGLk/jrQaxTgR8KMTxSVcISwTEa3FrDLnI8KjBXvej26BSztvLF0q7l43CpLkh\n chNjthRTuy8aH6a5rW9o4Cvr3QkJnwymL1NbaitcuuR2U5BFxHsay5BtaXIzPtW0ZJDw\n FqprLLNASGm1Pa2bjmhEUIGoQco6XCN87vPVSSWjxLaqUwG86rqJ3HEIC/LTs3FZ4KTg\n 8a7w=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776470179; c=relaxed/simple;\n bh=5vNGr+LerlC7drkM4d4HDEvbw8rIx9HNEyzr2LaelJY=;\n h=DKIM-Signature:DKIM-Signature:MIME-Version:From:Date:Message-ID:\n Subject:To;\n b=dqveWCGDhS/j/RL3K/vZ4FPaH0txGlo5keMG+QUEpfY+xAR1DdWKV6H/ipu1RSyDcmGzabJdgHBTHl0Py+dwPiNYqksWvXB7xy37X8PXYyggvK0DHB6bTMk3Tt0AIMTUTIiC14VPJXTbG78F3Y/iF8GjG0e2MW5FKnpwU6aRGik=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:dkim-signature;\n bh=mghoeCmFBwETuPY1pQ9BCxyII0JYVBTXV79dDpp0dPQ=;\n fh=mcOGApQkSFNeTB11IhJAh97zncgwGdrCjCk6ifYIdEI=;\n b=k8VIJC6jswdSo1l10Wm2VA6QnNok+1TWa3zydCq1NpU+s/kpb4uI2g06cCKYMxBM/O\n qtol6U0M/1wR0IRQL9oNfWLa4fPQVGMGv4h6CGP72/KvT0tGF2BLkhAftYD7JAHCj//+\n 2fJlqDU9PBptMpcmgTSVgmiRDn+5E/6ww0Y9LCUqHZBUdns3wpORWasLUJCuIBXOnFHO\n 6YGDqQL8dVYxjt0dpDs0v0jLB05tTn0haO8lG9LSUsWzcTHdRe89DqsHLw7ZdxLGIeuQ\n R0a0FZDigxcxuYcWN7/ia9uJmfNvMRVkyFPBFKlBRHQT9pFmS8T6stavFFqG23JKrnSN\n EnNw==; darn=gcc.gnu.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:content-type:date:from:in-reply-to\n :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n mghoeCmFBwETuPY1pQ9BCxyII0JYVBTXV79dDpp0dPQ=; b=h69eE1N3744lL3Z/\n 7jO9jLQ3fvu4kmPYP91rj3HWo7/TE1hMueDbppMG32IRWf4ksCAp0u1y8iOEMLbm\n ezYMOjW1TmGzSMDwynAoHj0P1bCXiNL9bKEFAYOt5MTJLT8+ttjhazXLvzqnMxmq\n a0oQP9vKo06BrqV+5qHmV6UX3ZMufzEKFHgFIFYk8rx94vfAX96vIqMMpGgHbnOM\n 6yrquU35hcDMsQ2hwl2yNCW0KeiSKmuUjVNhQWNIdC+vqTgDyScpZo15wHjGiWy6\n 3Etnaz4b47G2LxqUQ08q3kSyhYv+/mqR0gG9Xs9lusB4WVtWPTfYkd6as+v3pLho\n FMiEGw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1776470178; x=1777074978; darn=gcc.gnu.org;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:from:to:cc:subject:date\n :message-id:reply-to;\n bh=mghoeCmFBwETuPY1pQ9BCxyII0JYVBTXV79dDpp0dPQ=;\n b=M8mjC6YQ+0nuDJVCfRu8TO1IyudG8NFPP5FAOmVwDGi5X/sDT0mq0t2xqX+5/cmJWt\n 5wtdbsi5N+o/OG7id9XOoHDxUwhrCsTUG++aJHbUyZoakViBnu0VECJQQRfDyRyjlpVk\n 7aQ8G+te2gNHQC9xF6ESORfwT4MKOSlJPmL7HynoxkChRAHmz09W61Dg7ptL8SDAs1fH\n WIoC0F4K+VDAdgD+jNlCOc9Dh0FXAAoho8pVEEoYns3TFBQViIo0oZ5cU7B3aljAyWZS\n oBXV3uMVi1fbXKnHfpBnLxOUcoyqGhwjvnen+ALeLdXItBFc+qmXgL9UFkIRrbjdRSp6\n w5SQ=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776470178; x=1777074978;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=mghoeCmFBwETuPY1pQ9BCxyII0JYVBTXV79dDpp0dPQ=;\n b=ChInQMBiH7SVaMo/Prhlt/EpClztuKbPAmYxbqfFReu/oH/x0C/k/OyMc8rX9R1Ild\n 9NUrCd66pvSud42KZg7yWeBNsaXpS394j9eWyFtk8nN9irZISOsq5auxx935A/YBJtyy\n /h9/yYv9y18FtqyeunMq49noUR3YViQyBDs1SRLCy+yH9SrElGPCynvASgEPtWHvouKN\n QSaI/kkCvmbIL+ntao4yj1EcCR02aCfRoI+aiHfLn4JPqRxxfn1JxZ6AZmsnHZs8H915\n XgoIG9cwIaZw608/OF/lx0T4D3rEm9tiPeOqcEyUFxvCTthoztRC8C96dZEdbtTAJzZw\n a+YA==","X-Gm-Message-State":"AOJu0Yz3UupmYvp/eD5rnvofS+IB3w3lmpn9OcWeyptXpFSji9DNhn7N\n IGyfy00jnbzhO4M7QszuIq5e8cIORD7MO01fBiZ2AJuCVpSdyj+RJmRO1fK5ihOe5DBlbWAT/wc\n OE4d+xWoEvHBdUz+2D5h4UH9ah+8nq19GL/pfsnCmuvHAixbmc1jFMyAxpX38i5QPRz4dDMDFJt\n dgfwI6f+X0/p5HSkuq0+nQuvRshRn6myzP9Bw=","X-Gm-Gg":"AeBDieuiAfbOWeQ8ncVUyfocqeKnEHIuqFW/2cIE2HS+m+uIeqRID2OlotanYqumBQO\n J1LUWo2N85U9IOma9/3N4PiHnyviN0FR8dQBF2JsdJWO/2zWtrmaURAceBMLbl8bE0cAqxDZ/JN\n N5dRtj9R4aWtCp9UCEjuFymSu+ORGpw+IerrmiKZUQbsq0IlH2su0lJb+OfsDS7UePPxbU+YQw2\n +JF6J76Fhnn5cw=","X-Received":["by 2002:a05:7300:1351:b0:2de:2f38:a7cb with SMTP id\n 5a478bee46e88-2e4788392f0mr2377105eec.18.1776470177576;\n Fri, 17 Apr 2026 16:56:17 -0700 (PDT)","by 2002:a05:7300:1351:b0:2de:2f38:a7cb with SMTP id\n 5a478bee46e88-2e4788392f0mr2377093eec.18.1776470177070; Fri, 17 Apr 2026\n 16:56:17 -0700 (PDT)"],"MIME-Version":"1.0","References":"<20260417233535.524431-1-hongtao.liu@intel.com>\n <CALvbMcCCn_D3DBwnp7QvFrsBOwRKha0tjJ1TYjO_GtDzoaLO0w@mail.gmail.com>","In-Reply-To":"\n <CALvbMcCCn_D3DBwnp7QvFrsBOwRKha0tjJ1TYjO_GtDzoaLO0w@mail.gmail.com>","From":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Date":"Fri, 17 Apr 2026 16:56:04 -0700","X-Gm-Features":"AQROBzAbX0zvpzuG-JkGkKUOBWrc-UKiR4ncWYzDUMVpYutKn5k9IjddwUoyRZc","Message-ID":"\n <CALvbMcCR1F4tVcmDeSRVo=5cU+sPJxPN_1w4XDBsB0JvF28DTw@mail.gmail.com>","Subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","To":"liuhongt <hongtao.liu@intel.com>","Cc":"gcc-patches@gcc.gnu.org, rguenther@suse.de","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-Proofpoint-ORIG-GUID":"2gVTsguCyyJ6iAENbgwvblMWFDMao9IY","X-Proofpoint-GUID":"2gVTsguCyyJ6iAENbgwvblMWFDMao9IY","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDE3MDIzOSBTYWx0ZWRfX1qZAOQ0sAsKf\n JKq/u+n9W2Y6L47uZjIic7XjZzp6AXrJKy9WfgDzA8/sX7V1sdO22J6/6oN9pUmQF0u9f73gCto\n 1pZXhUZFvnjEehx9oGxxHBXa8mUi6smHLFUyatj8ih+tLoZhfVSiBwyGi+Q4ckKJKZbKja4vNsC\n Gg/QQIgzI73R9AG4w7xMIMRnYoIAPYtqKrV/0J01WhbDvf2Hy5pTup7Hy0yZ4FQS7kc4tLJnBv0\n fityDl+8R0nSQtWFIvD1oNnHCzntDr0Yt3ShZp/2x6ifC5GseTH9Dipo8Fv9g2AX5zG4mMRkhWj\n semMPv+SxHxquqCdboiIOOXqFk28NtsLnjdTUkV5dlM4mGjLrzXA285ScPi6XeEDmccJnKPvjdz\n ARxCcxuQNs748vI/zwmELfV/zvuZV5xQhTnVZWABcHmHIbLFiGZN9LY7kcENQi9iEjD72OTBbDu\n eoKvk978Vvk/LAhua6g==","X-Authority-Analysis":"v=2.4 cv=PKw/P/qC c=1 sm=1 tr=0 ts=69e2c8a2 cx=c_pps\n a=cFYjgdjTJScbgFmBucgdfQ==:117 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10\n a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22\n a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=QyXUC8HyAAAA:8 a=6gl_cCoBAAAA:8\n a=KKSMjP8iyoIALho2S-AA:9 a=QEXdDO2ut3YA:10 a=scEy_gLbYbu1JhEsrz4S:22\n a=Bor9z-CvbNo2M6AZn8_k: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-17_03,2026-04-17_04,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n spamscore=0 suspectscore=0 phishscore=0 priorityscore=1501 adultscore=0\n lowpriorityscore=0 malwarescore=0 impostorscore=0 clxscore=1015 bulkscore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604170239","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"}},{"id":3678915,"web_url":"http://patchwork.ozlabs.org/comment/3678915/","msgid":"<CAMZc-bzWYJunX7S9hijhFEtUHh8OPOgY8Oy_XVEbqL+9mVYyDw@mail.gmail.com>","list_archive_url":null,"date":"2026-04-18T00:01:18","subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","submitter":{"id":75791,"url":"http://patchwork.ozlabs.org/api/people/75791/","name":"Hongtao Liu","email":"crazylht@gmail.com"},"content":"On Sat, Apr 18, 2026 at 7:56 AM Andrew Pinski\n<andrew.pinski@oss.qualcomm.com> wrote:\n>\n> On Fri, Apr 17, 2026 at 4:45 PM Andrew Pinski\n> <andrew.pinski@oss.qualcomm.com> wrote:\n> >\n> > On Fri, Apr 17, 2026 at 4:36 PM liuhongt <hongtao.liu@intel.com> wrote:\n> > >\n> > > DSE can forward-substitute a stored value into a load and then delete\n> > > the store as dead.  This leaves REG_EQUAL notes on other insns that\n> > > reference the same memory location stale, since the memory now holds\n> > > a different (older) value.\n> > >\n> > > When late-combine propagates a register source into such a stale\n> > > REG_EQUAL note, the note can end up with two identical MEM references\n> > > (e.g. (minus (mem[X]) (mem[X]))) that simplify_binary_operation folds\n> > > to zero.  IRA then promotes REG_EQUAL(0) to REG_EQUIV(0), and reload\n> > > eliminates the computation entirely, producing wrong code.\n> > >\n> > > Fix this by dropping REG_EQUAL/REG_EQUIV notes that contain any\n> > > non-readonly MEM before propagating into them.  Read-only MEMs (such\n> > > as constant pool references) are safe since their contents cannot\n> > > change.  REG_EQUAL notes are just optimization hints, so dropping\n> > > them is always safe.\n> > >\n> > >\n> > > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.\n> > > Ok for trunk?\n> >\n> > I am not sure this is the right approach reading the bug report. I\n> > thought it was mentioned this REG_EQUAL should never have been created\n> > in the first place.\n> > Can you see where the REG_EQUAL with the MEM was added in the first\n> > place and try not to add it there?\n> > I don't see why there is a REG_EQUAL anyways there.\n> > Plus since we don't have a LLM policy in place I am not going to\n> > review this patch otherwise.\n>\n> Also it is NOT the job of a different pass to fix up a problem from a\n> different pass. That is a very fragile approach.\n\nI believe this fix is safer at the stage4 phase. Simply dropping all\nmemory-related reg_equal notes sounds like it could lead to some\nperformance regression.\n\n>\n> >\n> > Thanks,\n> > Andrew\n> >\n> > >\n> > > gcc/ChangeLog:\n> > >\n> > >         PR rtl-optimization/124894\n> > >         * rtl.h (contains_nonreadonly_mem_rtx_p): Declare.\n> > >         * rtlanal.cc (contains_nonreadonly_mem_rtx_p): New function.\n> > >         * late-combine.cc (insn_combination::substitute_note): Drop\n> > >         REG_EQUAL/REG_EQUIV notes that reference non-readonly MEM.\n> > >\n> > > gcc/testsuite/ChangeLog:\n> > >\n> > >         PR rtl-optimization/124894\n> > >         * gcc.dg/pr124894.c: New test.\n> > >\n> > > Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>\n> > > ---\n> > >  gcc/late-combine.cc             | 11 ++++++++++\n> > >  gcc/rtl.h                       |  1 +\n> > >  gcc/rtlanal.cc                  | 13 ++++++++++++\n> > >  gcc/testsuite/gcc.dg/pr124894.c | 36 +++++++++++++++++++++++++++++++++\n> > >  4 files changed, 61 insertions(+)\n> > >  create mode 100644 gcc/testsuite/gcc.dg/pr124894.c\n> > >\n> > > diff --git a/gcc/late-combine.cc b/gcc/late-combine.cc\n> > > index aeb3ba17615..069d6b21161 100644\n> > > --- a/gcc/late-combine.cc\n> > > +++ b/gcc/late-combine.cc\n> > > @@ -350,6 +350,17 @@ insn_combination::substitute_note (insn_info *use_insn, rtx note,\n> > >    if (REG_NOTE_KIND (note) == REG_EQUAL\n> > >        || REG_NOTE_KIND (note) == REG_EQUIV)\n> > >      {\n> > > +      // If the note references a MEM, drop it rather than propagating\n> > > +      // into it.  The MEM's value may have been changed by a store that\n> > > +      // was later deleted (e.g. by DSE), making the note stale.\n> > > +      // Propagating into such a note could produce incorrect\n> > > +      // simplifications (e.g. (minus (mem) (mem)) folded to zero when\n> > > +      // the two references actually correspond to different values).\n> > > +      // Read-only MEMs are safe, since their contents cannot change.\n> > > +      // Since the note is just a hint, it is always safe to drop it.\n> > > +      if (contains_nonreadonly_mem_rtx_p (XEXP (note, 0)))\n> > > +       return false;\n> > > +\n> > >        insn_propagation prop (use_insn->rtl (), m_dest, m_src);\n> > >        return (prop.apply_to_note (&XEXP (note, 0))\n> > >               && (can_propagate || prop.num_replacements == 0));\n> > > diff --git a/gcc/rtl.h b/gcc/rtl.h\n> > > index eebcc18a4f1..a5ccdadcfc2 100644\n> > > --- a/gcc/rtl.h\n> > > +++ b/gcc/rtl.h\n> > > @@ -3765,6 +3765,7 @@ extern rtx tablejump_casesi_pattern (const rtx_insn *insn);\n> > >  extern bool computed_jump_p (const rtx_insn *);\n> > >  extern bool tls_referenced_p (const_rtx);\n> > >  extern bool contains_mem_rtx_p (rtx x);\n> > > +extern bool contains_nonreadonly_mem_rtx_p (rtx x);\n> > >  extern bool register_asm_p (const_rtx);\n> > >\n> > >  /* Overload for refers_to_regno_p for checking a single register.  */\n> > > diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc\n> > > index 88561a54e5a..70c75a0dee3 100644\n> > > --- a/gcc/rtlanal.cc\n> > > +++ b/gcc/rtlanal.cc\n> > > @@ -710,6 +710,19 @@ contains_mem_rtx_p (rtx x)\n> > >    return false;\n> > >  }\n> > >\n> > > +/* Return true if X contains a MEM subrtx whose contents might change.  */\n> > > +\n> > > +bool\n> > > +contains_nonreadonly_mem_rtx_p (rtx x)\n> > > +{\n> > > +  subrtx_iterator::array_type array;\n> > > +  FOR_EACH_SUBRTX (iter, array, x, ALL)\n> > > +    if (MEM_P (*iter) && !MEM_READONLY_P (*iter))\n> > > +      return true;\n> > > +\n> > > +  return false;\n> > > +}\n> > > +\n> > >  /* Return true if X is an address that is known to not be zero.  */\n> > >\n> > >  bool\n> > > diff --git a/gcc/testsuite/gcc.dg/pr124894.c b/gcc/testsuite/gcc.dg/pr124894.c\n> > > new file mode 100644\n> > > index 00000000000..f906169c699\n> > > --- /dev/null\n> > > +++ b/gcc/testsuite/gcc.dg/pr124894.c\n> > > @@ -0,0 +1,36 @@\n> > > +/* { dg-do run } */\n> > > +/* { dg-require-effective-target int128 } */\n> > > +/* { dg-require-effective-target lp64 } */\n> > > +/* { dg-options \"-O2 -fno-strict-aliasing\" } */\n> > > +\n> > > +/* PR rtl-optimization/124894 */\n> > > +/* DSE can delete a store after forward-substituting the stored value into\n> > > +   a load, leaving a stale MEM in a REG_EQUAL note.  Late-combine must not\n> > > +   propagate into such notes, as the resulting simplification (e.g.\n> > > +   (minus (mem) (mem)) -> 0) would be wrong.  */\n> > > +\n> > > +short s;\n> > > +__int128 z;\n> > > +long g;\n> > > +\n> > > +__attribute__((noipa)) long\n> > > +foo (short a)\n> > > +{\n> > > +  long t = 0;\n> > > +  char c = *(char *) __builtin_memset (&z, 2, 6);\n> > > +  __builtin_memset (&s, c, 2);\n> > > +  __builtin_memmove (&t, &g, 4);\n> > > +  long u = -t;\n> > > +  long v = *(long *) __builtin_memset (&t, a | 6, 8);\n> > > +  __int128 w = z % s;\n> > > +  long r = w + t + u + v;\n> > > +  return r;\n> > > +}\n> > > +\n> > > +int\n> > > +main ()\n> > > +{\n> > > +  long x = foo (0);\n> > > +  if (x != 0x0c0c0c0c0c0c0c0c)\n> > > +    __builtin_abort ();\n> > > +}\n> > > --\n> > > 2.34.1\n> > >","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=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=e0173Cjy;\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=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=e0173Cjy","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","sourceware.org; spf=pass smtp.mailfrom=gmail.com","server2.sourceware.org;\n arc=pass smtp.remote-ip=74.125.224.46"],"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 4fyBkc3xlZz1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 10:01:59 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 657B84C318A4\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 00:01:57 +0000 (GMT)","from mail-yx1-f46.google.com (mail-yx1-f46.google.com\n [74.125.224.46])\n by sourceware.org (Postfix) with ESMTPS id C1BD24BA2E23\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 00:01:29 +0000 (GMT)","by mail-yx1-f46.google.com with SMTP id\n 956f58d0204a3-651bc83e74aso1255425d50.2\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 17:01:29 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 657B84C318A4","OpenDKIM Filter v2.11.0 sourceware.org C1BD24BA2E23"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org C1BD24BA2E23","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org C1BD24BA2E23","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1776470489; cv=pass;\n b=Bm8qjr8SppzkXygZeUBreW6RovrPHwp/D/0hDu+xwBCZb+qv8HMnlsjGAuI20MWnSLT0L+NLC/zSMYu6VC+FvKb9b4YPKjBrMhDGCs28ZpY24O1vv9SmwULl7m8aYxTmmhVkr22Y6WeUa8eEpcTIKdTOWCsN76Grrh0ZbZzGo2k=","i=1; a=rsa-sha256; t=1776470489; cv=none;\n d=google.com; s=arc-20240605;\n b=jlTx7n8axfcPZJ3GmGNNIjVtQXKD3D0cFUiU1wE4OueEfnOlEqFrXGDhf4qCXegYrH\n XvyupY7L7D0HmGUqyhUkJcmdqKQzcyAmKQosdFqp4XeTmhLtzIgEu6lmhrGaTRq7xmYR\n D1mVSgf3GMJ9HFIV8TzJkAkx92baxPd96LhDNjS4XB7xvOUrsgnceryTSz7WMvKsu1lI\n GvojqJGPz/nnKolBfUq/chAowSlplt5fSkzBo3C6ezyGdmEaskTQFp8hEkUbwBF/zKST\n QXSA06hHeJg5P+Up1/BO8WEUbM7bwDAeYsOvbBwfLdrOYVaYQAVV4JkxlxWqBZPaK9pB\n 3PKw=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776470489; c=relaxed/simple;\n bh=z6/DXrO2UvuVZ6THPxzquoBfGyQNyCdAIOxzaY0Xzq4=;\n h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To;\n b=xeSs5PAicPEWk3ZlLybYry/DddIiSC0X6skImHdlsOzO7mnsWLxytDR1BJZq5Wjx7sAaGTxbPIG+eOJuclVnX1t7a6DJg2f4Jp2YOS5nElXOSpQjk+/pkEDadf3e3jqcjaJiK3Tbun9Kbujf3I1zPQnX49/33pLaypTxyVFbhyI=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:dkim-signature;\n bh=R0+Y/BbbJAPgt9u0SmFaHqt8WBTvmf1L3mBfQL7+OCM=;\n fh=QOsRASgfIO7ltxjdGIoAzJJobIJFZ+vFWPcAGBI4xZk=;\n b=Rc8wcD/5v8MsEDtFR3cTtE8y/T0G8ssZTps7borkIfTUPjeQ1jv14mzejXvpU0mwop\n PZ/AkGQEiBq9HmsSxRoIVmOJxCrtPjpW3np9YMj3qODTTT7sT/R8qFi44oH6GfGznzWo\n OLZSIaFD145U+JtEu+kOlNjiTN8kp23z3mITd1yCre7on+Hjdhv+3teTatIyEcvJ3oDd\n eWQAjoiiQrqCCLGyoT8sosjJ/puWXaIzeM2qD5QzNZNOxsM45Cci1kdMhFI/rfkTyk8m\n NYAbQqVwoN7KVxvO+qDM4rn82+QeHt5m9CAj4GHt/jW2O3e30Tq+3OzJWJ2+qyDiEWH1\n 5uSA==; darn=gcc.gnu.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1776470489; x=1777075289; darn=gcc.gnu.org;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:from:to:cc:subject:date\n :message-id:reply-to;\n bh=R0+Y/BbbJAPgt9u0SmFaHqt8WBTvmf1L3mBfQL7+OCM=;\n b=e0173CjyitDM/CLr+bqsxIQQqsP9Qz6DgAehjgufpT3ZCAnv8PgqcI8vDya8+zUswB\n EyfkGVPjOplEZcwyRzYzgdLEjgX+bdBXK2e6MNeu3ArNRy18WiyeXzWO1aQ4+ASWwzlL\n /zmi9kAdn9NqWPPqZ6Idz6M2LnMU21DvevcQ2lJ44NqGCfeW46tZqQFx5FDHjOL58O+m\n gtPO0zjxo9jc6KEu1Tm5gF4HqFisKsaDdwrlzP3mMQ3928FeXBX6pAWbprBWeNi0GIRA\n bft5LzIT2J+CTmElQaxuw/AJg3HTrOu0L8NB2t294HlU9zHy/vXlJMdHtWqWAq1+W6We\n 6gPg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776470489; x=1777075289;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=R0+Y/BbbJAPgt9u0SmFaHqt8WBTvmf1L3mBfQL7+OCM=;\n b=q8G6aC25pW84DPbUWREUkD449uQL0WamjE0bHnB0vtMvXd3IwcZLNq0UHR6nxbYluc\n zMgntiWtJ0sRx2WDDHEyrSX4GiBUgPlx/gYVNGXSdDYhGEkAO5fpbqekn3oYMbu7mLjw\n b9EiR/76oxq1kL/224Vw+Ns5rwS9OWaXlzbqxwM7QV4cLwqWZa5GwIWhs3p60EXbX1zl\n cES8kkCEr1bN+b6nITc17hi/pKUEhIxv/5CkOld23vwYGKN3BpzjUE7dHvGn9qOf/U65\n KAtRyFabyiGps49VFF1pZNPQcdUED1fIDenD+j6yN3GBiNsHhPTFkRoSgpb8TeoT7qQV\n gZwg==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8V0XSWUVgsg5HwpfBZtc+IwZftMX+jcLcJV0ZX3FCLUNmEeE2zE6mSXeAA+fKTre9bMZwyKqv45pFO3w==@gcc.gnu.org","X-Gm-Message-State":"AOJu0Yxim9hjb/PU/Sl5O4YWdq+mbrzwEAdfp7490NWQOCFn62GJ7GrG\n SJoRZYxBnPXIO5Yul0GQTyMMsmOXt2NDM1bd3S/P9zSGMdWw0HXOA0v8syG3ATQRLwkk3qLzdQg\n qKPISlsrpbOiPFPN6qQtfD0iKX13kJJU=","X-Gm-Gg":"AeBDietqgrauf8cy+O+C0B9ztR2oNCC2O/wBtx4REtKFdxMze57KKkBTu7SwFHdAlU9\n 9fjiFU6Gc/uCdeFXUfyukKCgFGujtfgBq+iUyGkUP2naH8oc9usgROorXd0aIfj8fWXrAJnJ5gt\n 2rUGuI5KQLaFIh66FiRennqKLs8LD/r4IzuUF/eZkTHC/bJma9Bbe8pLvkMI9te/6ie+/Uc9FXv\n rlc4e6mhuRjZVFz7a95skxO/eBz6rMSCTxz5uNEfWESR4REPa8QtFihT5P6DVWu5XMKy1ymgh8b\n qcBZRyDavdzYSsMobF8=","X-Received":"by 2002:a05:690e:c42:b0:651:c734:ed4b with SMTP id\n 956f58d0204a3-653107f5a5bmr4884099d50.2.1776470488989; Fri, 17 Apr 2026\n 17:01:28 -0700 (PDT)","MIME-Version":"1.0","References":"<20260417233535.524431-1-hongtao.liu@intel.com>\n <CALvbMcCCn_D3DBwnp7QvFrsBOwRKha0tjJ1TYjO_GtDzoaLO0w@mail.gmail.com>\n <CALvbMcCR1F4tVcmDeSRVo=5cU+sPJxPN_1w4XDBsB0JvF28DTw@mail.gmail.com>","In-Reply-To":"\n <CALvbMcCR1F4tVcmDeSRVo=5cU+sPJxPN_1w4XDBsB0JvF28DTw@mail.gmail.com>","From":"Hongtao Liu <crazylht@gmail.com>","Date":"Sat, 18 Apr 2026 08:01:18 +0800","X-Gm-Features":"AQROBzBus8_GQJilPimphcfcZMGKYtmprOsPAhUPGKrqZtDDwLu9NpCdjpzd5IE","Message-ID":"\n <CAMZc-bzWYJunX7S9hijhFEtUHh8OPOgY8Oy_XVEbqL+9mVYyDw@mail.gmail.com>","Subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","To":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Cc":"liuhongt <hongtao.liu@intel.com>, gcc-patches@gcc.gnu.org,\n rguenther@suse.de","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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"}},{"id":3678919,"web_url":"http://patchwork.ozlabs.org/comment/3678919/","msgid":"<CALvbMcBDNa44EWSo8fEjW4ZdBXtbkhKZ8QYuLWOARptdHERCVg@mail.gmail.com>","list_archive_url":null,"date":"2026-04-18T00:08:36","subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","submitter":{"id":91428,"url":"http://patchwork.ozlabs.org/api/people/91428/","name":"Andrew Pinski","email":"andrew.pinski@oss.qualcomm.com"},"content":"On Fri, Apr 17, 2026 at 5:01 PM Hongtao Liu <crazylht@gmail.com> wrote:\n>\n> On Sat, Apr 18, 2026 at 7:56 AM Andrew Pinski\n> <andrew.pinski@oss.qualcomm.com> wrote:\n> >\n> > On Fri, Apr 17, 2026 at 4:45 PM Andrew Pinski\n> > <andrew.pinski@oss.qualcomm.com> wrote:\n> > >\n> > > On Fri, Apr 17, 2026 at 4:36 PM liuhongt <hongtao.liu@intel.com> wrote:\n> > > >\n> > > > DSE can forward-substitute a stored value into a load and then delete\n> > > > the store as dead.  This leaves REG_EQUAL notes on other insns that\n> > > > reference the same memory location stale, since the memory now holds\n> > > > a different (older) value.\n> > > >\n> > > > When late-combine propagates a register source into such a stale\n> > > > REG_EQUAL note, the note can end up with two identical MEM references\n> > > > (e.g. (minus (mem[X]) (mem[X]))) that simplify_binary_operation folds\n> > > > to zero.  IRA then promotes REG_EQUAL(0) to REG_EQUIV(0), and reload\n> > > > eliminates the computation entirely, producing wrong code.\n> > > >\n> > > > Fix this by dropping REG_EQUAL/REG_EQUIV notes that contain any\n> > > > non-readonly MEM before propagating into them.  Read-only MEMs (such\n> > > > as constant pool references) are safe since their contents cannot\n> > > > change.  REG_EQUAL notes are just optimization hints, so dropping\n> > > > them is always safe.\n> > > >\n> > > >\n> > > > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.\n> > > > Ok for trunk?\n> > >\n> > > I am not sure this is the right approach reading the bug report. I\n> > > thought it was mentioned this REG_EQUAL should never have been created\n> > > in the first place.\n> > > Can you see where the REG_EQUAL with the MEM was added in the first\n> > > place and try not to add it there?\n> > > I don't see why there is a REG_EQUAL anyways there.\n> > > Plus since we don't have a LLM policy in place I am not going to\n> > > review this patch otherwise.\n> >\n> > Also it is NOT the job of a different pass to fix up a problem from a\n> > different pass. That is a very fragile approach.\n>\n> I believe this fix is safer at the stage4 phase. Simply dropping all\n> memory-related reg_equal notes sounds like it could lead to some\n> performance regression.\n\nSince this is NOT a P1 and it was already in a shipping compiler, it\ncan wait until stage 1 and then backported for GCC 16.2.0 and the next\n15.x when it is shown there is not a big performance regression.\nAlso I doubt there is a performance regression since REG_EQUAL with a\nmem on the RTL level is not going to be used that much anyways.\nREG_EQUAL is being used less and less these days after gimple was\nadded 20+ years ago.\n\nThanks,\nAndrew\n\n>\n> >\n> > >\n> > > Thanks,\n> > > Andrew\n> > >\n> > > >\n> > > > gcc/ChangeLog:\n> > > >\n> > > >         PR rtl-optimization/124894\n> > > >         * rtl.h (contains_nonreadonly_mem_rtx_p): Declare.\n> > > >         * rtlanal.cc (contains_nonreadonly_mem_rtx_p): New function.\n> > > >         * late-combine.cc (insn_combination::substitute_note): Drop\n> > > >         REG_EQUAL/REG_EQUIV notes that reference non-readonly MEM.\n> > > >\n> > > > gcc/testsuite/ChangeLog:\n> > > >\n> > > >         PR rtl-optimization/124894\n> > > >         * gcc.dg/pr124894.c: New test.\n> > > >\n> > > > Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>\n> > > > ---\n> > > >  gcc/late-combine.cc             | 11 ++++++++++\n> > > >  gcc/rtl.h                       |  1 +\n> > > >  gcc/rtlanal.cc                  | 13 ++++++++++++\n> > > >  gcc/testsuite/gcc.dg/pr124894.c | 36 +++++++++++++++++++++++++++++++++\n> > > >  4 files changed, 61 insertions(+)\n> > > >  create mode 100644 gcc/testsuite/gcc.dg/pr124894.c\n> > > >\n> > > > diff --git a/gcc/late-combine.cc b/gcc/late-combine.cc\n> > > > index aeb3ba17615..069d6b21161 100644\n> > > > --- a/gcc/late-combine.cc\n> > > > +++ b/gcc/late-combine.cc\n> > > > @@ -350,6 +350,17 @@ insn_combination::substitute_note (insn_info *use_insn, rtx note,\n> > > >    if (REG_NOTE_KIND (note) == REG_EQUAL\n> > > >        || REG_NOTE_KIND (note) == REG_EQUIV)\n> > > >      {\n> > > > +      // If the note references a MEM, drop it rather than propagating\n> > > > +      // into it.  The MEM's value may have been changed by a store that\n> > > > +      // was later deleted (e.g. by DSE), making the note stale.\n> > > > +      // Propagating into such a note could produce incorrect\n> > > > +      // simplifications (e.g. (minus (mem) (mem)) folded to zero when\n> > > > +      // the two references actually correspond to different values).\n> > > > +      // Read-only MEMs are safe, since their contents cannot change.\n> > > > +      // Since the note is just a hint, it is always safe to drop it.\n> > > > +      if (contains_nonreadonly_mem_rtx_p (XEXP (note, 0)))\n> > > > +       return false;\n> > > > +\n> > > >        insn_propagation prop (use_insn->rtl (), m_dest, m_src);\n> > > >        return (prop.apply_to_note (&XEXP (note, 0))\n> > > >               && (can_propagate || prop.num_replacements == 0));\n> > > > diff --git a/gcc/rtl.h b/gcc/rtl.h\n> > > > index eebcc18a4f1..a5ccdadcfc2 100644\n> > > > --- a/gcc/rtl.h\n> > > > +++ b/gcc/rtl.h\n> > > > @@ -3765,6 +3765,7 @@ extern rtx tablejump_casesi_pattern (const rtx_insn *insn);\n> > > >  extern bool computed_jump_p (const rtx_insn *);\n> > > >  extern bool tls_referenced_p (const_rtx);\n> > > >  extern bool contains_mem_rtx_p (rtx x);\n> > > > +extern bool contains_nonreadonly_mem_rtx_p (rtx x);\n> > > >  extern bool register_asm_p (const_rtx);\n> > > >\n> > > >  /* Overload for refers_to_regno_p for checking a single register.  */\n> > > > diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc\n> > > > index 88561a54e5a..70c75a0dee3 100644\n> > > > --- a/gcc/rtlanal.cc\n> > > > +++ b/gcc/rtlanal.cc\n> > > > @@ -710,6 +710,19 @@ contains_mem_rtx_p (rtx x)\n> > > >    return false;\n> > > >  }\n> > > >\n> > > > +/* Return true if X contains a MEM subrtx whose contents might change.  */\n> > > > +\n> > > > +bool\n> > > > +contains_nonreadonly_mem_rtx_p (rtx x)\n> > > > +{\n> > > > +  subrtx_iterator::array_type array;\n> > > > +  FOR_EACH_SUBRTX (iter, array, x, ALL)\n> > > > +    if (MEM_P (*iter) && !MEM_READONLY_P (*iter))\n> > > > +      return true;\n> > > > +\n> > > > +  return false;\n> > > > +}\n> > > > +\n> > > >  /* Return true if X is an address that is known to not be zero.  */\n> > > >\n> > > >  bool\n> > > > diff --git a/gcc/testsuite/gcc.dg/pr124894.c b/gcc/testsuite/gcc.dg/pr124894.c\n> > > > new file mode 100644\n> > > > index 00000000000..f906169c699\n> > > > --- /dev/null\n> > > > +++ b/gcc/testsuite/gcc.dg/pr124894.c\n> > > > @@ -0,0 +1,36 @@\n> > > > +/* { dg-do run } */\n> > > > +/* { dg-require-effective-target int128 } */\n> > > > +/* { dg-require-effective-target lp64 } */\n> > > > +/* { dg-options \"-O2 -fno-strict-aliasing\" } */\n> > > > +\n> > > > +/* PR rtl-optimization/124894 */\n> > > > +/* DSE can delete a store after forward-substituting the stored value into\n> > > > +   a load, leaving a stale MEM in a REG_EQUAL note.  Late-combine must not\n> > > > +   propagate into such notes, as the resulting simplification (e.g.\n> > > > +   (minus (mem) (mem)) -> 0) would be wrong.  */\n> > > > +\n> > > > +short s;\n> > > > +__int128 z;\n> > > > +long g;\n> > > > +\n> > > > +__attribute__((noipa)) long\n> > > > +foo (short a)\n> > > > +{\n> > > > +  long t = 0;\n> > > > +  char c = *(char *) __builtin_memset (&z, 2, 6);\n> > > > +  __builtin_memset (&s, c, 2);\n> > > > +  __builtin_memmove (&t, &g, 4);\n> > > > +  long u = -t;\n> > > > +  long v = *(long *) __builtin_memset (&t, a | 6, 8);\n> > > > +  __int128 w = z % s;\n> > > > +  long r = w + t + u + v;\n> > > > +  return r;\n> > > > +}\n> > > > +\n> > > > +int\n> > > > +main ()\n> > > > +{\n> > > > +  long x = foo (0);\n> > > > +  if (x != 0x0c0c0c0c0c0c0c0c)\n> > > > +    __builtin_abort ();\n> > > > +}\n> > > > --\n> > > > 2.34.1\n> > > >\n>\n>\n>\n> --\n> BR,\n> Hongtao","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=SgE/oc69;\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=Y9hSU+Hr;\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=SgE/oc69;\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=Y9hSU+Hr","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=pass smtp.remote-ip=205.220.168.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 4fyBv66z5dz1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 10:09:21 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 9B1204CD201D\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 00:09:19 +0000 (GMT)","from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com\n [205.220.168.131])\n by sourceware.org (Postfix) with ESMTPS id 4A1FA4BA23E7\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 00:08:50 +0000 (GMT)","from pps.filterd (m0279863.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63HIRwj32434104\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 00:08:49 GMT","from mail-dy1-f200.google.com (mail-dy1-f200.google.com\n [74.125.82.200])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dkt5mrqjh-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 00:08:48 +0000 (GMT)","by mail-dy1-f200.google.com with SMTP id\n 5a478bee46e88-2da19227bc1so3167691eec.1\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 17:08:48 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 9B1204CD201D","OpenDKIM Filter v2.11.0 sourceware.org 4A1FA4BA23E7"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 4A1FA4BA23E7","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 4A1FA4BA23E7","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1776470930; cv=pass;\n b=WSDH13aJdUN1yPopJyk8Tiqt4ma+eas7k0yVmxFW+RskAqq/h4sWkq2zxYC8J3SurpLCEMw1XLDGMpSWSJEgOpXZnduac666XStRiUUlx92pVZSH9CSzdo7kj0ZZZcWcEwT/5jJqVt1bXDjJ30C0uLN2IQQIdzzgLFE6TsjDlis=","i=1; a=rsa-sha256; t=1776470928; cv=none;\n d=google.com; s=arc-20240605;\n b=hQESLRa1UkHkZctBRvzcUeDvqSci5njPMBZEk6U7F0fLYRg9FK6OfJptxHrWcGeNMQ\n 88FtYeuUgBKchjuyMYySf4EiHF9aX1pwhrp9Vh4x5UUQGG4PnQBYYLj5sUmMN2mHDQ9Y\n BJPLcfmwpLYpURR33QMAMg4EzOxT/HO8mNlEHH1pGamXC9BRCv9yR66vFxuKHv6y3qhl\n lhosFXiurANkviHTmqr0Y6IisLFx9ydUZw7sQlt+ePDiSq15M4AZbMwCXyoaPUDRG1Xx\n qTs6EpENQbwShQmRJSFuZokp5tOnqHk/nc36tSSL/90sGRwBeqw4LJnNOyiFp74nYxMw\n iKhA=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776470930; c=relaxed/simple;\n bh=QhOTd0mU9oDOUZ+lhALqAhzvAV3vXNDbMgP+ADaNQ2w=;\n h=DKIM-Signature:DKIM-Signature:MIME-Version:From:Date:Message-ID:\n Subject:To;\n b=sjrZopG0wOJfvXFoJZFuDsfTtVhSlzZt6wKxS5lll5bjF4SRfoy67hvqYUTGPRCBT5MB64HjbDC2NRoMto+JQEIWyZxO4dD2jATxwnsm1GjOTmpxAOaCkIiOji67QlYdscDqj3D9RittOUy32mp+pETfihe3fKG81WJySqHgOe4=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:dkim-signature;\n bh=QJAgb+s0Dk+NaxtCMSpH5yZVaBOJMxWKva/FFgBIdQw=;\n fh=cp/b1PnvPEKYtlzNeYanqd+LdsagsnccCEPzYfNyKj8=;\n b=RSMFpHyUPBOiJUFzFphvBeMMLfdHptse6igOfl+h7cgp8F6eOl4OePY3C3WUu3Hrax\n bFCjMPnMRPlmwb/IGF0pTbbg27tREI2QjoXnTDAb7zh2FOJKjsgtjdtbVp1wHtynBLYV\n 2w1LKXM7pKcklMRR6Txrj3roZtRodiMPN1pHqDb8LVH7+4to9nAXEIQpn3wpnHWE7Pvg\n j4MHwZC1Z/wflKg8RoQDd2yRxs12a98o4azWEpiRYKOiU1bSRw8At2CbzcVsM9TG1B5P\n 5Tv4/XBLwwYyfrVH9wb08D/yslQqYvzjTeJR6F8LQw2mkfZHGW7ppL8OZc+kRux4PSgE\n LSsA==; darn=gcc.gnu.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:content-type:date:from:in-reply-to\n :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n QJAgb+s0Dk+NaxtCMSpH5yZVaBOJMxWKva/FFgBIdQw=; b=SgE/oc69NaFaYY+U\n EsncBSQMdCXfakS5M/q2UKn9gmalDj5/pmwR9LijCD5H/zs608+Pv4YNdNKB3cNb\n Ae/XQsUv99hz7clZxsKy4LFlbysrm0Lo1HgIiW1h/PAm94G+8KNsJ9MzbOYiw9fG\n gqTJqeqNTzWStxcthNzqSPuQFPCeLv+Q2EYbUSDl0j5hz57WQTaOq/1uaiU0HamL\n lP+UXFJDU5KGj59DzNHYups15BF7LCpDg/IsXUpa1/yyNbRsNFPSG6Kjgezez5YK\n b0BP3cXMQCJVAQmpqgZY3Cc29NjgyeANeWSuv2VnyXxEVg4i48MZi/jmqgrAlMyo\n aPiYbA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1776470928; x=1777075728; darn=gcc.gnu.org;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:from:to:cc:subject:date\n :message-id:reply-to;\n bh=QJAgb+s0Dk+NaxtCMSpH5yZVaBOJMxWKva/FFgBIdQw=;\n b=Y9hSU+HrFqbPglECT5ao7aKbX0rAEoxGL+WdJEMu3pD23s1qBFbPNQB7EJENc9MVAu\n nBH62oJnXMlRB1l94+r7WTGfoooMug3wg3XMpTP6N6thHsBjmlGeeiS6TaQiNmAy8Ms3\n YaPxKxVAbDTcyiCTGzOIsedW09YNx6HkxVQOrH01loiRSdqCNNSQfx/4VlWI1vuHNud1\n LqD0FeuR5GjOcK/Mo415yhB54CprnbB6qv7u9rnS+Yunminu9vjMthEjk44EM+L/8GQP\n O+mAscnW7hf1+WgtwMAGZmFPYm8c7ihralw3I3EGZUzzb4UYNRgZi+oKberZ9O0LEcaW\n hUzA=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776470928; x=1777075728;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=QJAgb+s0Dk+NaxtCMSpH5yZVaBOJMxWKva/FFgBIdQw=;\n b=YRbRWT/QLJcwCDBbl2t26NU9Kqo3jYNFh12Hs26LOUhJ/3QbN1UpIOnbMGkewITu+Y\n 6ZP6BMVgbNtrc07+hkaOKet8jakrehGTkzYjVRIlay/Xtn6S+bzA2CUpkD2lUlApC1nV\n GbtO4ComKZLqiMOvdQALZM9cDeLAv/Md9/TuLePuRrPDYaeSbq/UBkBbIzpfS3LNPEXM\n PprZH0BDz8y2QYpQVkqNns5wclFT9uzj0+ta7arAc2f8dBMtd2cNveRpwnMqpjq9Mddw\n KcCveCAl+3VHAbUM8ie/cSBf8Is0xS9PJHOI8+D/JskiSaUVCqJ/jF0z3JioD/sX1+WD\n uGJw==","X-Forwarded-Encrypted":"i=1;\n AFNElJ+OTmdujvQSJ0F2EG6YqQa+lhf3LDWYzfgDEVyUlDXR55Ue5prR9FKgDLCdBOK+m8lyZaB9KnIwnr/UyQ==@gcc.gnu.org","X-Gm-Message-State":"AOJu0YyvLud3ecy0ucMi/fGOBGjU3mzwANJJiROwneZPKmcfl3qv1n5/\n 3CUUiC/l1SWEDvqgGaFjSHs+OzYYxJtZET5nZwqlxE1XJj+TeU51651cQt/HJ/aeawLpNOP9mwQ\n u62wEs2OyMHEtXBMufqYw/jqp9/Yprj+52yHtw+qdCi7n3IMVi9pm1qv3cG5gcarMyR8nuBsqYt\n Vx2pFcWeJBIHJBmNxdWyjfBXrS0xVbShQsfNs=","X-Gm-Gg":"AeBDiesBhYzRCDpUM1yZgnoGSF3wcxb3IEK/Z2eiDX3EY7NIQD+Jk1AxbHcVwq45mzp\n /jVGAZ8mpTee79NJ4SjJ/kMz89fB9JE1WJjBoheu5PFqwHV1m5z0d1NUwuaKChOVVNPRpVNynPT\n mOXAHnBYoJTvKEk7IsBFqSsB1z1vFImrwfXslhCtL4f1CDkku1MXy3NAa6MgbZSIRHifFUMmkHX\n pPc/fFLWxhAkY0=","X-Received":["by 2002:a05:7301:2e85:b0:2d2:d7b7:5c70 with SMTP id\n 5a478bee46e88-2e4786461a9mr3009073eec.15.1776470928093;\n Fri, 17 Apr 2026 17:08:48 -0700 (PDT)","by 2002:a05:7301:2e85:b0:2d2:d7b7:5c70 with SMTP id\n 5a478bee46e88-2e4786461a9mr3009055eec.15.1776470927505; Fri, 17 Apr 2026\n 17:08:47 -0700 (PDT)"],"MIME-Version":"1.0","References":"<20260417233535.524431-1-hongtao.liu@intel.com>\n <CALvbMcCCn_D3DBwnp7QvFrsBOwRKha0tjJ1TYjO_GtDzoaLO0w@mail.gmail.com>\n <CALvbMcCR1F4tVcmDeSRVo=5cU+sPJxPN_1w4XDBsB0JvF28DTw@mail.gmail.com>\n <CAMZc-bzWYJunX7S9hijhFEtUHh8OPOgY8Oy_XVEbqL+9mVYyDw@mail.gmail.com>","In-Reply-To":"\n <CAMZc-bzWYJunX7S9hijhFEtUHh8OPOgY8Oy_XVEbqL+9mVYyDw@mail.gmail.com>","From":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Date":"Fri, 17 Apr 2026 17:08:36 -0700","X-Gm-Features":"AQROBzBgJLpgsGecj032ZaYXJy7fnznftkfB91snebiX0uaOE0-CU0JY7mAS3zw","Message-ID":"\n <CALvbMcBDNa44EWSo8fEjW4ZdBXtbkhKZ8QYuLWOARptdHERCVg@mail.gmail.com>","Subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","To":"Hongtao Liu <crazylht@gmail.com>","Cc":"liuhongt <hongtao.liu@intel.com>, gcc-patches@gcc.gnu.org,\n rguenther@suse.de","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-Authority-Analysis":"v=2.4 cv=AOj9hFqm c=1 sm=1 tr=0 ts=69e2cb90 cx=c_pps\n a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10\n a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22\n a=yOCtJkima9RkubShWh1s:22 a=pGLkceISAAAA:8 a=EUspDBNiAAAA:8 a=QyXUC8HyAAAA:8\n a=6gl_cCoBAAAA:8 a=DhvnIEnxilAk5Eiv3WEA:9 a=QEXdDO2ut3YA:10\n a=6Ab_bkdmUrQuMsNx7PHu:22 a=Bor9z-CvbNo2M6AZn8_k:22","X-Proofpoint-GUID":"JADJGJUFRB28pFhg1oVoT7Ufj0iARUkY","X-Proofpoint-ORIG-GUID":"JADJGJUFRB28pFhg1oVoT7Ufj0iARUkY","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDE3MDI0MiBTYWx0ZWRfX/lZfWG5HcWIc\n 4BmaSRi6pMoxHBsmeIjC8c26LkCAVuNZulgjYJp9vmYzrjqA1StLzVxjVv4ylkC0/N277oYUDFP\n nScwuzqxGrAjOkwGN9emaMbn9gSQQatfGIVPTvf2Pyooqku5prNcpeo0XLIDFZ/Y1cGlXJ3WTlb\n oYmpWDVUnkEi8oiCQUexywlE6q1Yi/NdhS8GS32bpB+mSXF7sivfEkbqTmv5/Ec2Mc1BNGwv8Mv\n KLQ/bataFsZYJRaZqzO+zMteThN0+kNKl1F/yKWVXlpC2Zc5ANDohjq7gTyWHXPCfFDrACXv/YM\n igpX8cARKsnbJTwe1A0+6KDc10YTp8TYzmtcAD5WoUEjU114qE09kkyRX/7qpIBo4466bOwrCE9\n zZ0RDbGBGQzjARrcMK3/G7/zJiNovbhhXBlbSrcyJ0E/s98ugbWFgHtzWYROi/cdwLd4J/RYzHQ\n RdbeUwuJHdxpGCNnuNA==","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-17_03,2026-04-17_04,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n bulkscore=0 clxscore=1015 priorityscore=1501 suspectscore=0 spamscore=0\n malwarescore=0 phishscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604170242","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"}},{"id":3678957,"web_url":"http://patchwork.ozlabs.org/comment/3678957/","msgid":"<12876456.O9o76ZdvQC@fomalhaut>","list_archive_url":null,"date":"2026-04-18T09:09:48","subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","submitter":{"id":5384,"url":"http://patchwork.ozlabs.org/api/people/5384/","name":"Eric Botcazou","email":"ebotcazou@libertysurf.fr"},"content":"> Also it is NOT the job of a different pass to fix up a problem from a\n> different pass. That is a very fragile approach.\n\nYes, REG_EQUAL/REG_EQUIV notes (unlike REG_DEAD/REG_UNUSED notes) cannot be \nrecomputed and, therefore, need to be properly maintained, so the patch is \npapering over the problem.","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=free.fr header.i=@free.fr header.a=rsa-sha256\n header.s=smtp-20201208 header.b=TeY28Wox;\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=free.fr header.i=@free.fr header.a=rsa-sha256\n header.s=smtp-20201208 header.b=TeY28Wox","sourceware.org; dmarc=none (p=none dis=none)\n header.from=libertysurf.fr","sourceware.org; spf=pass smtp.mailfrom=libertysurf.fr","server2.sourceware.org;\n arc=none smtp.remote-ip=212.27.42.3"],"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 4fyQvQ1RV9z1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 19:10:24 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 0FB944CD2023\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 09:10:22 +0000 (GMT)","from smtp3-g21.free.fr (smtp3-g21.free.fr [212.27.42.3])\n by sourceware.org (Postfix) with ESMTPS id 843184C9176F\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 09:09:54 +0000 (GMT)","from fomalhaut.localnet (unknown\n [IPv6:2a01:e0a:107c:2f10:e654:e8ff:fe8f:2ce6])\n (Authenticated sender: ebotcazou@libertysurf.fr)\n by smtp3-g21.free.fr (Postfix) with ESMTPSA id D0AB013F854;\n Sat, 18 Apr 2026 11:09:48 +0200 (CEST)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 0FB944CD2023","OpenDKIM Filter v2.11.0 sourceware.org 843184C9176F"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 843184C9176F","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 843184C9176F","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776503394; cv=none;\n b=CPe44Ns6SUx6UegNliaX9R1YPjAzVt2zSjCgSLVDyvezSSdw0Y0XN2UGr/Nu4uYPFIIceIUCU1v7rCG0Xx91Zw3j89Y+gfV0LHrKOgEd42hZjqWiuYUueWX096hPy/mDJ3jRVaI5LpsNzDaik8z50ugJEOGgLB2gKx9p1cWLlvA=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776503394; c=relaxed/simple;\n bh=gN2/ipAPqGuY9tq2rmTAewrhN2Fc2K0DUPx5LtsifNg=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=EUxfG68Xz9Apn8VCHplC6KkBoxIGeEpunHAO0MTQMIgxlTawLdoBpW0X6QXDQ/5UbiiOqanfsZSwJUyjAKlU0UFvikYZgb6V2Y04mWpUp1b0KoK8IGJMlMf38zQZpImSi1t9lgMRMPTihS/Cbxal1nNuaMK0Y0LH0LnzmxamccA=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr;\n s=smtp-20201208; t=1776503392;\n bh=gN2/ipAPqGuY9tq2rmTAewrhN2Fc2K0DUPx5LtsifNg=;\n h=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n b=TeY28WoxkFSrnHwnCU4r+WDLJk+qA6FudQLHgPEG2g1yseeIA90vmU8HLfmSCSlhh\n YUOYscMJmUX/xqzEpC9YgJ186Ihu0/SD/AguzZw7KNLOf5s0TwxrWRwXvWwbciXr7z\n kPCvyCzpuaUoeK2Pux4N6fNaCqztIwcZ7kaE0bFHX74X56y7aVF4MQwPyPgI2Jlcsf\n EDexHkXfBTccK7swTMSCYF5PNEbs0DZ0dCPYZxqeauc16RCQoMnIoDWFTuWIhcoJz4\n I724zNb6qIn7iCOr5FfTKpa//new+6y2EoPEKCIFvnfY2FVzZis6E/8Ar3s07cWGsC\n DR//PHOkXtxeA==","From":"Eric Botcazou <ebotcazou@libertysurf.fr>","To":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Cc":"liuhongt <hongtao.liu@intel.com>, gcc-patches@gcc.gnu.org,\n rguenther@suse.de","Subject":"Re: [PATCH] late-combine: Don't substitute REG_EQUAL/REG_EQUIV notes\n that reference MEM [PR124894]","Date":"Sat, 18 Apr 2026 11:09:48 +0200","Message-ID":"<12876456.O9o76ZdvQC@fomalhaut>","In-Reply-To":"\n <CALvbMcCR1F4tVcmDeSRVo=5cU+sPJxPN_1w4XDBsB0JvF28DTw@mail.gmail.com>","References":"<20260417233535.524431-1-hongtao.liu@intel.com>\n <CALvbMcCCn_D3DBwnp7QvFrsBOwRKha0tjJ1TYjO_GtDzoaLO0w@mail.gmail.com>\n <CALvbMcCR1F4tVcmDeSRVo=5cU+sPJxPN_1w4XDBsB0JvF28DTw@mail.gmail.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"7Bit","Content-Type":"text/plain; charset=\"utf-8\"","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"}}]