Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2227513/?format=api
{ "id": 2227513, "url": "http://patchwork.ozlabs.org/api/patches/2227513/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260423211141.7906-1-netanelkomm@gmail.com/", "project": { "id": 17, "url": "http://patchwork.ozlabs.org/api/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, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260423211141.7906-1-netanelkomm@gmail.com>", "list_archive_url": null, "date": "2026-04-23T21:11:41", "name": "[v2] tree-optimization: lower mempcpy to memcpy when result is unused [PR93556]", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "9b10d045c8d4e6217cf0ea088444412c30b27b80", "submitter": { "id": 92716, "url": "http://patchwork.ozlabs.org/api/people/92716/?format=api", "name": "Netanel Komm", "email": "netanelkomm@gmail.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260423211141.7906-1-netanelkomm@gmail.com/mbox/", "series": [ { "id": 501245, "url": "http://patchwork.ozlabs.org/api/series/501245/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=501245", "date": "2026-04-23T21:11:41", "name": "[v2] tree-optimization: lower mempcpy to memcpy when result is unused [PR93556]", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/501245/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2227513/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2227513/checks/", "tags": {}, "related": [], "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=DhOa4jnu;\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=DhOa4jnu", "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.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 4g1pkJ6rwKz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 07:13:55 +1000 (AEST)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 1A8554B99F4C\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 21:13:52 +0000 (GMT)", "from mail-wm1-f46.google.com (mail-wm1-f46.google.com\n [209.85.128.46])\n by sourceware.org (Postfix) with ESMTPS id 87C214BAE7FF\n for <gcc-patches@gcc.gnu.org>; Thu, 23 Apr 2026 21:13:23 +0000 (GMT)", "by mail-wm1-f46.google.com with SMTP id\n 5b1f17b1804b1-488a8ca4aadso97911115e9.3\n for <gcc-patches@gcc.gnu.org>; Thu, 23 Apr 2026 14:13:23 -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-488fc1c0354sm506732505e9.11.2026.04.23.14.13.20\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 23 Apr 2026 14:13:21 -0700 (PDT)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 1A8554B99F4C", "OpenDKIM Filter v2.11.0 sourceware.org 87C214BAE7FF" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 87C214BAE7FF", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 87C214BAE7FF", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776978803; cv=none;\n b=i4aQ5IJMwprR+6q5UQyxaLpVTTS2qnGCQtsguJb808kF9T/SU13lVMYSGJ0Jgq9AjoWk8l0Hd7QeVGtrX3KqN9RLbQK1oZkx03IN7rwLs1movg+NqxqGdAx6X68aaQP7+7YPQ9N8RBPoTt3x/4oAXSCKGse8mILv1elhFNeGltk=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776978803; c=relaxed/simple;\n bh=HYX8Y0BdjQgLBxgkHznUorogVPhgaoLlUZXCuzgpnv8=;\n h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version;\n b=XhVwOaz7v4Pb5cGdIUWNsK+XbDdqNLfDbJOAMcex7VhUdbl3m8zfuArueAuQEpqtG9UmfM7X/rlZm52h7wUCC2hz9Bsr1skHT5l4mVlv06zwFOb3Z2CFNPMMWcKc7oLkegRaCL7TOiowfXt2if5WOpEM9Rp0VIiLh7gJHn8wpOg=", "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=1776978802; x=1777583602; 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=j1muMLktKxF7/cFRpBUHabq4ltQA49BXcU9Z0XoFeU4=;\n b=DhOa4jnuo2LFhtFFQrCG+SL1dndU1FWvUqZ5JfTuxpAAMuyAdEsoZzbzDEfsFJgPg7\n sGZG379O+EBQXe1ZfjmixsijfxThm6wXVpSnTrCXXkgvPApDc8bOIZKJkheQ5UyCH6qj\n NdiLrADuhv5XqTUqPVVnE2JLY5qEt48+7B681WjyaSMfIlejVkt4savELPq8+nPLg7iX\n 5Q+oKmzzXd9UgrrPUVfF6ZXlSHW3wUT4Bt7jqHNwCGATrn9mhlZpjQQL0m395MiJ+fD8\n k3T7NIydGfZ+nz+ZZEkU+KncmDUCsXCFrGwzODW7Zq1rLuFwHO57CVm7DSW28/nBWlN2\n 7Aag==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776978802; x=1777583602;\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=j1muMLktKxF7/cFRpBUHabq4ltQA49BXcU9Z0XoFeU4=;\n b=Fw8uD0e4Oj8yWvnHR+e9Jbs+T2Y90iGn3E+77qoTaHPyAneY5TIo/9nFt8B1UyoGUP\n GHg/Y5Pjtlfsn8V49vZQ2RZ5lMCUpQZMXJNADEHJWTc4HKsnrO3MyB6Gt0P/ehMLMqKS\n vL/s0uzMxMpxyuJD5eSDBcgLQy8BItFgRk8M++xPMo9JHL/s6y11gVtYsV8VW5mF2JTa\n sgLdMont1YlyuWC8IvejZfukEB5yB8a37Ewm0NTKPd5d87pacc8/+4EKTJLzw4GdGTuM\n 6s3RPo/WdYzjs/uV+2riNz6zN1jKJRoSnavhgwj2EMXVJeI0KmmhxdKUGy0ourwZ+6Tf\n ev3g==", "X-Gm-Message-State": "AOJu0YxR4+884QjSrwyLuRLeYjsJoaeYlE8i5fuOYQHxPqEqL0hSP7PD\n /6eiPdK2WpMsZRqp89e8O4+sYP63D0JKYIKuHUz9qB+E9vR04xyjUa6bC1TUklyF", "X-Gm-Gg": "AeBDiet/X4gU/Zcd+aFeWTbhKu6UuMDP8XcpTFu3/1RvJNPeMgV8gWTKFxUuh3XXymA\n cdffMiXRzblLDgkoSOzr1qSjqTln279BNozRlptmKYBwTyKp6CTol148sPEW9nB95ECuEJc/516\n C9dty/Sb1RJKXk5U5p2QjpmX9iNQbrkXA8PBnKDLjYW9XuHt+F7BmGGqWiCMSggcEGQYx+yqvKr\n DVs4CXyNTMRpfwZbKkYEzOiVHxROJeq/gmIZeeLy2KQXqqBC8gKgagmH11LwDNWQ4XlT36iPoDo\n qpsDY/cuIMyVYbFiugb2IAwXHhUTyGpqyRqcf5TSKZaG/JSR0VClNXErass5GT5CWElpcimfMet\n AyhSccjeMEFveRY2yQncT60NA8YgjbhljeobwTjYTyuPAljQC0Ga+Urgy4Bfo2snHS1mmnny877\n w/Y0Vwps4W938ez/u6HVTlzAFL1XK5vmWgqpljfgQrfXKXa/8bivmvWv0YaN5I2JTF+KUUjXD5h\n D8nlwLzBgMNWBxTQmY=", "X-Received": "by 2002:a05:600c:3110:b0:487:2439:b7be with SMTP id\n 5b1f17b1804b1-488fb7389dfmr430399755e9.6.1776978801467;\n Thu, 23 Apr 2026 14:13:21 -0700 (PDT)", "From": "Netanel Komm <netanelkomm@gmail.com>", "To": "gcc-patches@gcc.gnu.org", "Cc": "andrew.pinski@oss.qualcomm.com, richard.guenther@gmail.com,\n Netanel Komm <netanelkomm@gmail.com>", "Subject": "[PATCH v2] tree-optimization: lower mempcpy to memcpy when result is\n unused [PR93556]", "Date": "Fri, 24 Apr 2026 00:11:41 +0300", "Message-Id": "<20260423211141.7906-1-netanelkomm@gmail.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20260225220131.75176-1-netanelkomm@gmail.com>", "References": "<20260225220131.75176-1-netanelkomm@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 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 | 28 ++++++-\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, 244 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 bc8540a8c5c..3c1a663ea2b 100644\n--- a/gcc/gimple-fold.cc\n+++ b/gcc/gimple-fold.cc\n@@ -3339,6 +3339,28 @@ 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+ {\n+ tree fn = builtin_decl_explicit (BUILT_IN_MEMCPY);\n+ if (!fn)\n+\treturn false;\n+ gimple_call_set_fndecl (stmt, fn);\n+ fold_stmt (gsi);\n+ return true;\n+ }\n+\n+ return false;\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 +5409,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": [ "v2" ] }