get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2228075,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2228075/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260425031612.5965-1-netanelkomm@gmail.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": "<20260425031612.5965-1-netanelkomm@gmail.com>",
    "date": "2026-04-25T03:16:12",
    "name": "[v3] tree-optimization: lower mempcpy to memcpy when result is unused [PR93556]",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "2e0cceac2bfe00c69caa80906130fd37ef9a3a5f",
    "submitter": {
        "id": 92716,
        "url": "http://patchwork.ozlabs.org/api/1.1/people/92716/?format=api",
        "name": "Netanel Komm",
        "email": "netanelkomm@gmail.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260425031612.5965-1-netanelkomm@gmail.com/mbox/",
    "series": [
        {
            "id": 501418,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/501418/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=501418",
            "date": "2026-04-25T03:16:12",
            "name": "[v3] tree-optimization: lower mempcpy to memcpy when result is unused [PR93556]",
            "version": 3,
            "mbox": "http://patchwork.ozlabs.org/series/501418/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2228075/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2228075/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=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=FyLPaAca;\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=FyLPaAca",
            "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=none smtp.remote-ip=209.85.128.45"
        ],
        "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 4g2Zmr4cVJz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 25 Apr 2026 13:19:07 +1000 (AEST)",
            "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 59E724BAD16B\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 25 Apr 2026 03:19:05 +0000 (GMT)",
            "from mail-wm1-f45.google.com (mail-wm1-f45.google.com\n [209.85.128.45])\n by sourceware.org (Postfix) with ESMTPS id BDC934BA9003\n for <gcc-patches@gcc.gnu.org>; Sat, 25 Apr 2026 03:18:36 +0000 (GMT)",
            "by mail-wm1-f45.google.com with SMTP id\n 5b1f17b1804b1-488d2079582so98512465e9.2\n for <gcc-patches@gcc.gnu.org>; Fri, 24 Apr 2026 20:18:36 -0700 (PDT)",
            "from natis-laptop.technion.ac.il (IGLD-84-229-254-210.inter.net.il.\n [84.229.254.210]) by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-488fb7bf7besm225237225e9.34.2026.04.24.20.18.34\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 24 Apr 2026 20:18:34 -0700 (PDT)"
        ],
        "DKIM-Filter": [
            "OpenDKIM Filter v2.11.0 sourceware.org 59E724BAD16B",
            "OpenDKIM Filter v2.11.0 sourceware.org BDC934BA9003"
        ],
        "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org BDC934BA9003",
        "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org BDC934BA9003",
        "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777087117; cv=none;\n b=GPBEb0pWOIczPukfn6vPHSfbKajUoxd02OIOnwSeqGgEuNEY9NogdQeTc3DPyKjzFHpq8wGndnRKKYrCuf2U6ajLdsV7alBU7XrFMzkWjlOTM2Kxp074LCJ0oYH0x2O734d0LqudpHH83xFRrmJLH8Pw3wsWjZoa2Mv4bsdB6Ac=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777087117; c=relaxed/simple;\n bh=/aGFo0mbHt22TY4HAcofnwlFZzN73Yof1GVSYW3nFlE=;\n h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version;\n b=NcBhvTzB8V422Wd/UG5b+5JAohmzgc4tRPiAGxiPueTVw9FgBD4JTmhNjbhaB6CcUXaHKO0ldIUMKDjuCzXIYdrIrNhkHw6/Q237TURr8UjodPtqtRh+Ge7YaBdd2hQlt4QwjfZ+P5MYl0louRrfSH3+BSw7wjpPUO3KAKFp3Yk=",
        "ARC-Authentication-Results": "i=1; server2.sourceware.org",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1777087115; x=1777691915; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=nJG8ZB2+hxZdSq07tGHiGMQPM/5V22h4uXJUjqEspX0=;\n b=FyLPaAcax7uaqUQxHR6UcUPri8hPdylzm9+nuANV7c0BgfPvfv6/EburLIxCCwV7Wp\n QgdMgIwrDNk4I4dfL4fokzdfKMyNUQOgJy0mTi7VG5SGp8szpzvi3r27U5lkscdWaoLn\n yr3yr6vSL49jQW38C6BxdKmMC3c1e5kXlNzSH5LCdv/2matvHg4e8alpaQJ+IyDqfXE4\n 7cacJNyQVjOsqvYub4sJoGWWq+n0SLFlYaA8Uqg4Nt6KSuqBgs8f61VXsv3jszJoR10z\n EdYMj2Eo5LAw6LBsMV1JYkjYw83z86Fm43h3BxIdvfN1Mg1622jTWYAaw4FdhGEgHM8J\n 81xA==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777087115; x=1777691915;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=nJG8ZB2+hxZdSq07tGHiGMQPM/5V22h4uXJUjqEspX0=;\n b=EW7Q6u82xZR80pEK9YpO+QvMiP5YFbRhe9o5UNC+mfQb/4M4QmDlR0cmFQrUal3pB2\n WAjSsO1VA5/MKz0r3kFORKrBXxjzGwA2Lor0ZGYMLZd8xdC/5J1j6/X4tT+ChON4z+H5\n ZOtnLOk+JCXnm1ci24F/ZKOnHVFqCdcJPytQ8/H1t3P+JnH6nQlr3zrdOv1n9waNx5QQ\n zzUSK1EO1cgpJ8YGh/v94JMLy0ThFHwjxvWEzIRIcpyBfp4qR3qk9Syy3E65HgJY9pMX\n TMnjBbwia2KsHD4Jw0LYBNEwI52MWIeMT9O2Eeo7CTi7OuBHmLHYOqN8DPPBYqmK0JEq\n 7PsQ==",
        "X-Gm-Message-State": "AOJu0YxO2PVbZPfWqWDQmWOihbgbUayJ+9lqpYptR3qWyQLlKy19hbc1\n VCV7ls+biqQmbxuMUJbWlKWrVqo1Q5kwdOJCjCYgQAxS44IhYrrweGkZnnm2vj7z",
        "X-Gm-Gg": "AeBDietsp4reCfWJgqdXPoaW5IhPSjeYMmgahWeGcly7H6Ty2wzzyj4XJij7iOnYBKn\n RwiGlCJCHNcQuZeWiAQz7SwXZg9o5ckNCveML+YICdOZ4S6ZF0JFTRuYZyMKF/yaeMz9BrzpEYw\n g3ePpaRWuHVunTktt5LncuPvnrwxCbwXEWrXkpRM6pR6aY1JOW6/mWAnE7Uk5lYcCmBCW345bpk\n 9JKrCzYLM2uBZNxWz4ygZqQLvCLSWUyjMp5ULDqCAN/scIahye91A+XcpdOmPpYLyVEJNLVB9BU\n zmJWQjGm/HAOsKeVYpadCZFUpsYMhnMo0YQ13/f9muf58gYEeKg7YVcJSJfjWq07BqUt2h30XLz\n vyuyJYG9WKtEkR2cMdWeev0G9Bpp03APczd1j++dq3WlW9xO+B8v74MfBU9Ti4VfaWAjkBVFWL0\n h0NnIXg/75ztyuR6CGZBgozxVuTSXChDSTqExRZKPry2/Vt+OksJoHOGMGYhAYFWTh8sHbpoAOP\n Ib90cp6Ar5fk+jPxCRYdijl9AolKg==",
        "X-Received": "by 2002:a05:600c:621a:b0:48a:592c:e642 with SMTP id\n 5b1f17b1804b1-48a592ce867mr236001925e9.18.1777087115058;\n Fri, 24 Apr 2026 20:18:35 -0700 (PDT)",
        "From": "Netanel Komm <netanelkomm@gmail.com>",
        "To": "gcc-patches@gcc.gnu.org",
        "Cc": "richard.guenther@gmail.com, andrew.pinski@oss.qualcomm.com,\n Netanel Komm <netanelkomm@gmail.com>",
        "Subject": "[PATCH v3] tree-optimization: lower mempcpy to memcpy when result is\n unused [PR93556]",
        "Date": "Sat, 25 Apr 2026 06:16:12 +0300",
        "Message-Id": "<20260425031612.5965-1-netanelkomm@gmail.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "\n <CAFiYyc2kA3nxqGEDT8Lg_cO9mH03F8NSZJ52HFHPB-OZrS3_xQ@mail.gmail.com>",
        "References": "\n <CAFiYyc2kA3nxqGEDT8Lg_cO9mH03F8NSZJ52HFHPB-OZrS3_xQ@mail.gmail.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "gcc-patches@gcc.gnu.org",
        "X-Mailman-Version": "2.1.30",
        "Precedence": "list",
        "List-Id": "Gcc-patches mailing list <gcc-patches.gcc.gnu.org>",
        "List-Unsubscribe": "<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>",
        "List-Archive": "<https://gcc.gnu.org/pipermail/gcc-patches/>",
        "List-Post": "<mailto:gcc-patches@gcc.gnu.org>",
        "List-Help": "<mailto:gcc-patches-request@gcc.gnu.org?subject=help>",
        "List-Subscribe": "<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>",
        "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"
    },
    "content": "This patch allows the GIMPLE folder to transform __builtin_mempcpy into __builtin_memcpy\nin cases where the return value is ignored. This is beneficial because most targets have\nan efficient implementation for memcpy.\n\nExisting tests that relied on the unfolded mempcpy have been duplicated - one version now\ntakes the folded mempcpy into account, and the other intentionally prevents the folding\nfrom happening.\n\nBootstrapped and regression tested on x86_64-linux-gnu.\n\n\tPR tree-optimization/93556\n\ngcc/ChangeLog:\n\n\t* gimple-fold.cc (gimple_fold_builtin_mempcpy): New function.\n\t(gimple_fold_builtin): Handle BUILT_IN_MEMPCPY.\n\ngcc/testsuite/ChangeLog:\n\n\t* gcc.dg/pr79223.c: Rename to gcc.dg/pr79223-1.c and update scans.\n\t* gcc.dg/tree-prof/val-prof-7.c: Rename to gcc.dg/tree-prof/val-prof-7-1.c and update scans.\n\t* gcc.dg/tree-ssa/builtins-folding-gimple-3.c: Update scans.\n\t* gcc.dg/builtin-mempcpy-1.c: New test.\n\t* gcc.dg/builtin-mempcpy-2.c: New test.\n\t* gcc.dg/pr79223-2.c: New test.\n\t* gcc.dg/tree-prof/val-prof-7-2.c: New test.\n\t* gcc.dg/tree-ssa/builtins-folding-gimple-4.c: New test.\n\nSigned-off-by: Netanel Komm <netanelkomm@gmail.com>\n---\nChanges in v3:\n - Rewrote gimple_fold_builtin_mempcpy to build a new gcall statement for memcpy and replace the mempcpy\n statement with it using the existing replace_call_with_call_and_fold helper. Bootstrapped and regression\n tested again.\n\nChanges in v2:\n - Switched from builtin_decl_implicit to builtin_decl_explicit for memcpy as it is required to be present.\n - Added a comment documenting gimple_fold_builtin_mempcpy.\n\n gcc/gimple-fold.cc                            | 32 +++++++-\n gcc/testsuite/gcc.dg/builtin-mempcpy-1.c      |  9 ++\n gcc/testsuite/gcc.dg/builtin-mempcpy-2.c      | 39 +++++++++\n .../gcc.dg/{pr79223.c => pr79223-1.c}         |  2 +-\n gcc/testsuite/gcc.dg/pr79223-2.c              | 38 +++++++++\n gcc/testsuite/gcc.dg/tree-prof/val-prof-7-1.c | 82 +++++++++++++++++++\n .../{val-prof-7.c => val-prof-7-2.c}          |  2 +-\n .../tree-ssa/builtins-folding-gimple-3.c      |  5 +-\n .../tree-ssa/builtins-folding-gimple-4.c      | 45 ++++++++++\n 9 files changed, 248 insertions(+), 6 deletions(-)\n create mode 100644 gcc/testsuite/gcc.dg/builtin-mempcpy-1.c\n create mode 100644 gcc/testsuite/gcc.dg/builtin-mempcpy-2.c\n rename gcc/testsuite/gcc.dg/{pr79223.c => pr79223-1.c} (86%)\n create mode 100644 gcc/testsuite/gcc.dg/pr79223-2.c\n create mode 100644 gcc/testsuite/gcc.dg/tree-prof/val-prof-7-1.c\n rename gcc/testsuite/gcc.dg/tree-prof/{val-prof-7.c => val-prof-7-2.c} (97%)\n create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-4.c",
    "diff": "diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc\nindex e9019e2c7bd..501c1245116 100644\n--- a/gcc/gimple-fold.cc\n+++ b/gcc/gimple-fold.cc\n@@ -3339,6 +3339,32 @@ gimple_fold_builtin_stpcpy (gimple_stmt_iterator *gsi)\n   return true;\n }\n \n+/* Simplify mempcpy call stmt at GSI, returning true if simplified.\n+   Currently only handling mempcpy -> memcpy when the return value\n+   is ignored.  */\n+\n+static bool\n+gimple_fold_builtin_mempcpy (gimple_stmt_iterator *gsi)\n+{\n+  gcall *stmt = as_a <gcall *> (gsi_stmt (*gsi));\n+\n+  if (gimple_call_lhs (stmt) != NULL_TREE)\n+    return false;\n+\n+  tree fn = builtin_decl_explicit (BUILT_IN_MEMCPY);\n+  if (!fn)\n+    return false;\n+\n+  tree dest = gimple_call_arg (stmt, 0);\n+  tree src = gimple_call_arg (stmt, 1);\n+  tree n = gimple_call_arg (stmt, 2);\n+\n+  gcall *repl = gimple_build_call (fn, 3, dest, src, n);\n+  replace_call_with_call_and_fold (gsi, repl);\n+\n+  return true;\n+}\n+\n /* Fold a call EXP to {,v}snprintf having NARGS passed as ARGS.  Return\n    NULL_TREE if a normal call should be emitted rather than expanding\n    the function inline.  FCODE is either BUILT_IN_SNPRINTF_CHK or\n@@ -5387,8 +5413,12 @@ gimple_fold_builtin (gimple_stmt_iterator *gsi)\n       return gimple_fold_builtin_memset (gsi,\n \t\t\t\t\t gimple_call_arg (stmt, 1),\n \t\t\t\t\t gimple_call_arg (stmt, 2));\n-    case BUILT_IN_MEMCPY:\n     case BUILT_IN_MEMPCPY:\n+      if (gimple_fold_builtin_memory_op (gsi, gimple_call_arg (stmt, 0),\n+\t\t\t\t\t    gimple_call_arg (stmt, 1), fcode))\n+\treturn true;\n+      return gimple_fold_builtin_mempcpy (gsi);\n+    case BUILT_IN_MEMCPY:\n     case BUILT_IN_MEMMOVE:\n       return gimple_fold_builtin_memory_op (gsi, gimple_call_arg (stmt, 0),\n \t\t\t\t\t    gimple_call_arg (stmt, 1), fcode);\ndiff --git a/gcc/testsuite/gcc.dg/builtin-mempcpy-1.c b/gcc/testsuite/gcc.dg/builtin-mempcpy-1.c\nnew file mode 100644\nindex 00000000000..19d9a224657\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/builtin-mempcpy-1.c\n@@ -0,0 +1,9 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-fdump-tree-lower\" } */\n+\n+/* Basic MRE from bug report */\n+void test_bare (void *d, const void *s, __SIZE_TYPE__ n) {\n+  __builtin_mempcpy (d, s, n);\n+}\n+\n+/* { dg-final { scan-tree-dump \"__builtin_memcpy\" \"lower\" } } */\ndiff --git a/gcc/testsuite/gcc.dg/builtin-mempcpy-2.c b/gcc/testsuite/gcc.dg/builtin-mempcpy-2.c\nnew file mode 100644\nindex 00000000000..65f80f97f4f\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/builtin-mempcpy-2.c\n@@ -0,0 +1,39 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-O1 -fdump-tree-optimized\" } */\n+\n+/* Indirectly unused result */\n+void test_unused_indirect (void *d, const void *s, __SIZE_TYPE__ n) {\n+  void *a = __builtin_mempcpy (d, s, n);\n+  void *b = a;\n+}\n+\n+/* Simple used result (in statement) */\n+void *test_used_simple (void *d, const void *s, __SIZE_TYPE__ n) {\n+  return __builtin_mempcpy (d, s, n);\n+}\n+\n+/* More complicated used result (in expression) */\n+__SIZE_TYPE__ test_used_in_expr (char *d, const char *s, __SIZE_TYPE__ n) {\n+  return (char *)__builtin_mempcpy (d, s, n) - d;\n+}\n+\n+/* Unused in all paths */\n+void *test_unused_indirect2 (void *d, const void *s, __SIZE_TYPE__ n) {\n+  void *a = __builtin_mempcpy (d, s, n);\n+  if (n > 20) {\n+\treturn (void *)20;\n+  }\n+  return (void *)7;\n+}\n+\n+/* Used in at least one path */\n+void *test_maybe_used (void *d, const void *s, __SIZE_TYPE__ n) {\n+  void *a = __builtin_mempcpy (d, s, n);\n+  if (n > 20) {\n+    return a;\n+  }\n+  return (void *)0;\n+}\n+\n+/* { dg-final { scan-tree-dump-times \"__builtin_memcpy\" 2 \"optimized\" } } */\n+/* { dg-final { scan-tree-dump-times \"__builtin_mempcpy\" 3 \"optimized\" } } */\ndiff --git a/gcc/testsuite/gcc.dg/pr79223.c b/gcc/testsuite/gcc.dg/pr79223-1.c\nsimilarity index 86%\nrename from gcc/testsuite/gcc.dg/pr79223.c\nrename to gcc/testsuite/gcc.dg/pr79223-1.c\nindex ef0dd1b7bc5..099d18333e8 100644\n--- a/gcc/testsuite/gcc.dg/pr79223.c\n+++ b/gcc/testsuite/gcc.dg/pr79223-1.c\n@@ -28,7 +28,7 @@ void test_memcpy (void)\n \n void test_mempcpy (void)\n {\n-  mempcpy (d, s, range ());   /* { dg-warning \".mempcpy. writing 4 or more bytes into a region of size 3 overflows the destination\" } */\n+  mempcpy (d, s, range ());   /* { dg-warning \".memcpy. writing 4 or more bytes into a region of size 3 overflows the destination\" } */\n }\n \n void test_memmove (void)\ndiff --git a/gcc/testsuite/gcc.dg/pr79223-2.c b/gcc/testsuite/gcc.dg/pr79223-2.c\nnew file mode 100644\nindex 00000000000..6e78b326671\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/pr79223-2.c\n@@ -0,0 +1,38 @@\n+/* PR middle-end/79223 - missing -Wstringop-overflow on a memmove overflow\n+   { dg-do compile }\n+   { dg-additional-options \"-O2 -Wall -Wno-array-bounds -std=gnu99\" }  */\n+\n+typedef __SIZE_TYPE__ size_t;\n+\n+extern void* memcpy (void*, const void*, size_t);\n+extern void* mempcpy (void*, const void*, size_t);\n+extern void* memmove (void*, const void*, size_t);\n+\n+char d[3];\n+char s[4];\n+void *sink;\n+\n+size_t range (void)\n+{\n+  extern size_t size ();\n+  size_t n = size ();\n+  if (n <= sizeof d)\n+    return sizeof d + 1;\n+\n+  return n;\n+}\n+\n+void test_memcpy (void)\n+{\n+  memcpy (d, s, range ());   /* { dg-warning \".memcpy. writing 4 or more bytes into a region of size 3 overflows the destination\" } */\n+}\n+\n+void test_mempcpy (void)\n+{\n+  sink = mempcpy (d, s, range ());   /* { dg-warning \".mempcpy. writing 4 or more bytes into a region of size 3 overflows the destination\" } */\n+}\n+\n+void test_memmove (void)\n+{\n+  memmove (d + 1, d, range ());   /* { dg-warning \".memmove. writing 4 or more bytes into a region of size 2 overflows the destination\" } */\n+}\ndiff --git a/gcc/testsuite/gcc.dg/tree-prof/val-prof-7-1.c b/gcc/testsuite/gcc.dg/tree-prof/val-prof-7-1.c\nnew file mode 100644\nindex 00000000000..321eefa8207\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/tree-prof/val-prof-7-1.c\n@@ -0,0 +1,82 @@\n+/* { dg-options \"-O2 -fdump-ipa-profile-optimized -mtune=core2\" } */\n+/* { dg-skip-if \"\" { ! { i?86-*-* x86_64-*-* } } } */\n+\n+char *buffer1;\n+char *buffer2;\n+\n+/* Bzero is not tested because it gets transformed into memset.  */\n+\n+#define DEFINE_TEST(N) \\\n+__attribute__((noinline)) \\\n+void memcpy_test_ ## N (int len) \\\n+{ \\\n+  __builtin_memcpy (buffer1, buffer2, len); \\\n+} \\\n+ \\\n+__attribute__((noinline)) \\\n+void mempcpy_test_ ## N (int len) \\\n+{ \\\n+  __builtin_mempcpy (buffer1, buffer2, len); \\\n+} \\\n+ \\\n+__attribute__((noinline)) \\\n+void memset_test_ ## N (int len) \\\n+{ \\\n+  __builtin_memset (buffer1, 'c', len); \\\n+} \\\n+__attribute__((noinline)) \\\n+void memmove_test_ ## N (int len) \\\n+{ \\\n+  __builtin_memmove (buffer1, buffer2, len); \\\n+} \\\n+ \\\n+void test_stringops_ ## N(int len) \\\n+{ \\\n+  memcpy_test_## N (len); \\\n+  mempcpy_test_ ## N (len); \\\n+  memset_test_ ## N (len); \\\n+  memmove_test_ ## N (len); \\\n+} \\\n+ \\\n+void test_stringops_with_values_ ## N (int common, int not_common) \\\n+{ \\\n+  int i; \\\n+  for (i = 0; i < 1000; i++) \\\n+    { \\\n+      if (i > 990) \\\n+\ttest_stringops_ ## N (not_common); \\\n+      else \\\n+\ttest_stringops_ ## N (common); \\\n+    } \\\n+}\n+\n+DEFINE_TEST(0);\n+DEFINE_TEST(1);\n+DEFINE_TEST(2);\n+\n+int main() {\n+  buffer1 = __builtin_malloc (1000);\n+  buffer2 = __builtin_malloc (1000);\n+\n+  test_stringops_with_values_0 (8, 55);\n+  test_stringops_with_values_1 (55, 55);\n+  test_stringops_with_values_2 (257, 55);\n+\n+  return 0;\n+}\n+\n+/* { dg-final-use-not-autofdo { scan-ipa-dump \"Transformation done: single value 8 stringop for BUILT_IN_MEMCPY\" \"profile\" } } */\n+/* { dg-final-use-not-autofdo { scan-ipa-dump \"Transformation done: single value 55 stringop for BUILT_IN_MEMCPY\" \"profile\" } } */\n+/* { dg-final-use-not-autofdo { scan-ipa-dump-times \"Transformation done: single value 32 stringop for BUILT_IN_MEMCPY\" 0 \"profile\" } } */\n+\n+/* { dg-final-use-not-autofdo { scan-ipa-dump \"Transformation done: single value 8 stringop for BUILT_IN_MEMCPY\" \"profile\" } } */\n+/* { dg-final-use-not-autofdo { scan-ipa-dump \"Transformation done: single value 55 stringop for BUILT_IN_MEMCPY\" \"profile\" } } */\n+/* { dg-final-use-not-autofdo { scan-ipa-dump-times \"Transformation done: single value 32 stringop for BUILT_IN_MEMPCPY\" 0 \"profile\" } } */\n+\n+/* { dg-final-use-not-autofdo { scan-ipa-dump \"Transformation done: single value 8 stringop for BUILT_IN_MEMSET\" \"profile\" } } */\n+/* { dg-final-use-not-autofdo { scan-ipa-dump \"Transformation done: single value 55 stringop for BUILT_IN_MEMSET\" \"profile\" } } */\n+/* { dg-final-use-not-autofdo { scan-ipa-dump-times \"Transformation done: single value 32 stringop for BUILT_IN_MEMSET\" 0 \"profile\" } } */\n+\n+/* { dg-final-use-not-autofdo { scan-ipa-dump \"Transformation done: single value 8 stringop for BUILT_IN_MEMMOVE\" \"profile\" } } */\n+/* { dg-final-use-not-autofdo { scan-ipa-dump \"Transformation done: single value 55 stringop for BUILT_IN_MEMMOVE\" \"profile\" } } */\n+/* { dg-final-use-not-autofdo { scan-ipa-dump-times \"Transformation done: single value 32 stringop for BUILT_IN_MEMMOVE\" 0 \"profile\" } } */\ndiff --git a/gcc/testsuite/gcc.dg/tree-prof/val-prof-7.c b/gcc/testsuite/gcc.dg/tree-prof/val-prof-7-2.c\nsimilarity index 97%\nrename from gcc/testsuite/gcc.dg/tree-prof/val-prof-7.c\nrename to gcc/testsuite/gcc.dg/tree-prof/val-prof-7-2.c\nindex 5ddb1a88c29..1084a852fc3 100644\n--- a/gcc/testsuite/gcc.dg/tree-prof/val-prof-7.c\n+++ b/gcc/testsuite/gcc.dg/tree-prof/val-prof-7-2.c\n@@ -16,7 +16,7 @@ void memcpy_test_ ## N (int len) \\\n __attribute__((noinline)) \\\n void mempcpy_test_ ## N (int len) \\\n { \\\n-  __builtin_mempcpy (buffer1, buffer2, len); \\\n+  void * volatile res = __builtin_mempcpy (buffer1, buffer2, len); \\\n } \\\n  \\\n __attribute__((noinline)) \\\ndiff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-3.c b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-3.c\nindex 716be5b8094..0872cc52a7f 100644\n--- a/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-3.c\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-3.c\n@@ -38,6 +38,5 @@ AR (memmove, int,   2, INT_MAX, 1);\n AR (mempcpy, short, 2, SHRT_MAX, 1);\n AR (mempcpy, int,   2, INT_MAX, 1);\n \n-/* { dg-final { scan-tree-dump-times \"builtin_memcpy\" 8 \"optimized\" } }\n-   { dg-final { scan-tree-dump-times \"builtin_memmove\" 2 \"optimized\" } }\n-   { dg-final { scan-tree-dump-times \"builtin_mempcpy\" 2 \"optimized\" } }  */\n+/* { dg-final { scan-tree-dump-times \"builtin_memcpy\" 10 \"optimized\" } }\n+   { dg-final { scan-tree-dump-times \"builtin_memmove\" 2 \"optimized\" } }  */\ndiff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-4.c b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-4.c\nnew file mode 100644\nindex 00000000000..0f0c577c64a\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-4.c\n@@ -0,0 +1,45 @@\n+/* PR 81908 - FAIL: gfortran.dg/alloc_comp_auto_array_2.f90 -O3 -g -m32\n+   Test to verify that calls to memcpy et al. where the size is in a range\n+   with more than one valid value are not eliminated (this test complements\n+   builtins-folding-gimple-2.c).\n+   { dg-do compile }\n+   { dg-options \"-O2 -Wall -fdump-tree-optimized\" } */\n+\n+#define SHRT_MAX   __SHRT_MAX__\n+#define SHRT_MIN   (-SHRT_MAX - 1)\n+#define INT_MAX    __INT_MAX__\n+#define INT_MIN    (-INT_MAX - 1)\n+\n+#define UNIQUE_FUNCNAME(func, line) test_ ## func ## _ ## line\n+#define FUNCNAME(func, line)        UNIQUE_FUNCNAME (func, line)\n+\n+void *sink;\n+\n+#define AR(func, type, min, max, val)\t\t\t\t\t\\\n+  void __attribute__ ((noclone, noinline))\t\t\t\t\\\n+  FUNCNAME (func, __LINE__) (char *d, const char *s, type n)\t\t\\\n+  {\t\t\t\t\t\t\t\t\t\\\n+    if ((type)min <= n && n <= (type)max)\t\t\t\t\\\n+      n = val;\t\t\t\t\t\t\t\t\\\n+    sink = __builtin_ ## func (d, s, n);\t\t\t\t\t\\\n+  } typedef void DummyType\n+\n+AR (memcpy, short, SHRT_MIN, 0, 1);\n+AR (memcpy, short, SHRT_MIN, 1, 2);\n+AR (memcpy, short, 2, SHRT_MAX, 1);\n+\n+AR (memcpy, int, INT_MIN, 0, 1);\n+AR (memcpy, int, INT_MIN, 1, 2);\n+AR (memcpy, int, INT_MIN, 2, 3);\n+AR (memcpy, int, 2, INT_MAX, 1);\n+AR (memcpy, int, 2, INT_MAX, 1);\n+\n+AR (memmove, short, 2, SHRT_MAX, 1);\n+AR (memmove, int,   2, INT_MAX, 1);\n+\n+AR (mempcpy, short, 2, SHRT_MAX, 1);\n+AR (mempcpy, int,   2, INT_MAX, 1);\n+\n+/* { dg-final { scan-tree-dump-times \"builtin_memcpy\" 8 \"optimized\" } }\n+   { dg-final { scan-tree-dump-times \"builtin_memmove\" 2 \"optimized\" } }\n+   { dg-final { scan-tree-dump-times \"builtin_mempcpy\" 2 \"optimized\" } }  */\n",
    "prefixes": [
        "v3"
    ]
}