Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2196960/?format=api
{ "id": 2196960, "url": "http://patchwork.ozlabs.org/api/patches/2196960/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260216175913.3513851-1-avi@scylladb.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": "<20260216175913.3513851-1-avi@scylladb.com>", "list_archive_url": null, "date": "2026-02-16T17:58:20", "name": "libstdc++: optimize std::uninitialized_move{, _n}() to memcpy when possible", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "6fae185b31969fc1044e3b1db2bd4e0659845a29", "submitter": { "id": 72515, "url": "http://patchwork.ozlabs.org/api/people/72515/?format=api", "name": "Avi Kivity", "email": "avi@scylladb.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260216175913.3513851-1-avi@scylladb.com/mbox/", "series": [ { "id": 492339, "url": "http://patchwork.ozlabs.org/api/series/492339/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=492339", "date": "2026-02-16T17:58:20", "name": "libstdc++: optimize std::uninitialized_move{, _n}() to memcpy when possible", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/492339/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2196960/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2196960/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=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=scylladb.com header.i=@scylladb.com header.a=rsa-sha256\n header.s=google header.b=RmhQo9Wx;\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=fail reason=\"signature verification failed\" (2048-bit key,\n unprotected) header.d=scylladb.com header.i=@scylladb.com header.a=rsa-sha256\n header.s=google header.b=RmhQo9Wx", "sourceware.org; dmarc=pass (p=reject dis=none)\n header.from=scylladb.com", "sourceware.org; spf=fail smtp.mailfrom=scylladb.com", "server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.221.41" ], "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 4fF9YC69Gvz1xtN\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 17 Feb 2026 05:00:10 +1100 (AEDT)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id CC5544BAD175\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 16 Feb 2026 18:00:07 +0000 (GMT)", "from mail-wr1-f41.google.com (mail-wr1-f41.google.com\n [209.85.221.41])\n by sourceware.org (Postfix) with ESMTPS id 040924B9DB6F\n for <gcc-patches@gcc.gnu.org>; Mon, 16 Feb 2026 17:59:16 +0000 (GMT)", "by mail-wr1-f41.google.com with SMTP id\n ffacd0b85a97d-43767807cf3so2572574f8f.1\n for <gcc-patches@gcc.gnu.org>; Mon, 16 Feb 2026 09:59:16 -0800 (PST)", "from avi.scylladb.com ([77.137.21.109])\n by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-43796a5d156sm31555451f8f.5.2026.02.16.09.59.14\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 16 Feb 2026 09:59:15 -0800 (PST)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org CC5544BAD175", "OpenDKIM Filter v2.11.0 sourceware.org 040924B9DB6F" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 040924B9DB6F", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 040924B9DB6F", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771264757; cv=none;\n b=aZhVTBd4/GZ1q9WwLNOXq1h5lOWnwXjPVUWwXje/C1P0oMtuJXvN+yWZ+gH/ZiwJgB8nPJdQ2QOb5oVIyurBHBmH3xYbxoPvowze75LmVIioPe8Pn/cbWfb+chdJYSOdxCZkeUlxnf7Bsq8GMcuGcosKau2ThA5RUWqw38ACCFs=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1771264757; c=relaxed/simple;\n bh=rDaScqzbGGYOEdJ1slKmnCtClU5MH/J2sDqVHMILaGc=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=ODaNjSb+rk4EBfPGZAqlTcDmIElepDkgLOaL7PwfnQT5dDC6NoPzcpsYIFklyFFtMmI6XsJG5BOT2wWX5+zsiBPZyR+5jgLMBCyS4YnNv7VIYHbmYh8PSgqbuqiV99JV8SRwXsn9jvaf3iRgSLQUuJyNtBKRyq50wTpryMnuNwc=", "ARC-Authentication-Results": "i=1; server2.sourceware.org", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=scylladb.com; s=google; t=1771264756; x=1771869556; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:from:to:cc:subject:date:message-id:reply-to;\n bh=6jaWG0EGOGuNasN6NSsw0KuIBvQDgxxkWRV1Mr6uZM0=;\n b=RmhQo9WxqkTbVTf87I6kTwEP15chFnzw/upzsgypo/f2+rGfjmQ4cduPqlil1HimTj\n 938uA9ir/HOJF2UlsjxAdLYcvFhIongcwEDoPqk5JH+M23PyvbiclLjdKMt08mdn/uUl\n B8uuFwvHlhPBiv6g0OjPP3PhFzRdVENajZ1IsI255ZQL3y5bRxrwtmTDVJ8X4bNE7Bup\n LCIdzhpGmjIimtV7A8lR9qnvYqPNGPCBO/QuWarttbGlSrYpg/d1OKf7V37Bd1nelFAX\n j0mv34nkBANhh+8eja3LFnDajG4gvB5mjBw/KjPNt9OwvPzX+sk5LR+zGUYK5224KNHw\n HjlA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1771264756; x=1771869556;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=6jaWG0EGOGuNasN6NSsw0KuIBvQDgxxkWRV1Mr6uZM0=;\n b=kLjOki7OY7U9aOal1Yj4P6q1J3EFcY0jJyqV/B0RRFg/A7SgZXBT0k/sgbH1XOon8m\n 0RWgo0I5devQR0xfbo4NvbMIUCsASdEHzzK786VCA1ZGD96Jm8kSom8qfZSlWXL3LLtC\n Q8voGUbSN2zvGOnfjJL26EJnv+YwawNq17FMSCNP4fg/36BKsAtfz2UNNwN4kA32vhc3\n vWs7B4/HSAeBFzIYJZ1zs6wykGGpKpG56346fwSU/5PLHYewU/kcm3dl7E+9+zeXcSvz\n 1HS+iZc6lxmHUlgy6yv35Q3V7ezicvwXXZO44ZCn+YnU+r9CGz9II1r7kifyz7DC1jsf\n nKUg==", "X-Gm-Message-State": "AOJu0YzeX7GGwfqJTJ3NjbW3gCVesKpkfQZ/Rj6ibFvLQ/zYjHgQNHoT\n 7SRqpTJSf9FlA9WBLTonO5ykiic4jH98HwEYcbepzt1T77RZ93R/NwFPIZmtXR7IGRItG1UZr2D\n ZFb9ywaJ9HaXMF/8FLkZOkWySs8S6WjIFAit6R74wxKjJtcwC2rfO1kNnMWBBxL5VoTy5oBpxOO\n hXe5EF7xLRE9sW1dw7VPrkcm9A8sxELUnk8KMwIZdMSkxDWACWE1oPsQklfnLh/U6ym/7DUBNn7\n acwmBKHMa+ccXovU/4GAITH6uO11uKxpVh59siow+cH0ZXgZ+H5GtBNH1blpNaTJwap8okVdIEv\n euLp54nA71jBvTF3gKguRVY4cjPgdg==", "X-Gm-Gg": "AZuq6aL8Avfn6eD9EUOPtIbrF58EhB7woNUAWYgfk0E1TuCrvZ3nPZlbCN84GHlcOP6\n VffwIRQrTaG5ODyb3EZ2Vnadw81Y8flh5/OgzEbkAd+SVhbLM0qYJsThPxVx9cOzMBR63hvCvTQ\n TMSyyEDpdxMVyzC6sdsJmoP2PJZsIQFhft/LZCFbqg9oWlhCaqmTPqy8fMu7TQlc1qvUWLqJ+j7\n VLa4FqDhjjbFnW9o8lY3so9njbFyR+C2Mokv/1rNs+No8KMQRRgkO1aOQ9lg8iQuB8QH7gmL0vc\n hnKVw5mc2u/WvrpW2yWymyCQaQp/cAlaV3gC2b6Xk6PL2Ruup9WtnOTesLMLkQMbCLq+IB29+gR\n 8ucTaBeQ+gx10Q6J0BldK363pfoJ3tnuYg1VgIrLVos/mj0SdOS8VpIH4hSBfSvfDylaGeU0u5K\n eGAQJCW7h+svccXaCULW9i3DHAFQyykp/+/jU=", "X-Received": "by 2002:a05:6000:4310:b0:436:8f7e:a479 with SMTP id\n ffacd0b85a97d-4379db33f6amr17089566f8f.17.1771264755588;\n Mon, 16 Feb 2026 09:59:15 -0800 (PST)", "From": "Avi Kivity <avi@scylladb.com>", "To": "libstdc++@gcc.gnu.org", "Cc": "gcc-patches@gcc.gnu.org", "Subject": "[PATCH] libstdc++: optimize std::uninitialized_move{,\n _n}() to memcpy when possible", "Date": "Mon, 16 Feb 2026 19:58:20 +0200", "Message-ID": "<20260216175913.3513851-1-avi@scylladb.com>", "X-Mailer": "git-send-email 2.53.0", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-CLOUD-SEC-AV-Sent": [ "true", "true" ], "X-CLOUD-SEC-AV-Info": [ "scylladb,google_mail,monitor", "scylla,google_mail,monitor" ], "X-Gm-Spam": [ "0", "0" ], "X-Gm-Phishy": [ "0", "0" ], "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": "std::uninitialized_move{,_n} delegates to the corresponding\nstd::uninitialized_copy() variant after wrapping with a move\niterator, but the std::uninitialized_copy() doesn't unwrap the\nmove iterator, therefore losing the memcpy optimization if the\niterators were just pointers.\n\nFix this by unwrapping the move iterator using __miter_base(). To\nprevent some greedy_ops tests starting to fail by consuming the\npointer difference, we have to unwrap the move iterator before computing\nthe iterator difference as well.\n\nlibstdc++v3/Changelog:\n\n PR libstdc++/121789\n * include/bits/stl_uninitialized.h (uninitialized_copy):\n Unwrap move iterators\n * testsuite/20_util/specialized_algorithms/uninitialized_move/121789.cc:\n New test.\n---\n\nDisclosure: I was assisted by AI.\n\n libstdc++-v3/include/bits/stl_uninitialized.h | 8 ++--\n .../uninitialized_move/121789.cc | 37 +++++++++++++++++++\n 2 files changed, 42 insertions(+), 3 deletions(-)\n create mode 100644 libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/121789.cc", "diff": "diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h b/libstdc++-v3/include/bits/stl_uninitialized.h\nindex 82e4ba2ff7b..fa9d896fefc 100644\n--- a/libstdc++-v3/include/bits/stl_uninitialized.h\n+++ b/libstdc++-v3/include/bits/stl_uninitialized.h\n@@ -273,11 +273,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n // We cannot tell when this condition is true in general,\n // so we rely on the __memcpyable trait.\n \n #if __cplusplus >= 201103L\n using _Dest = decltype(std::__niter_base(__result));\n- using _Src = decltype(std::__niter_base(__first));\n+ using _Src = decltype(std::__miter_base(std::__niter_base(__first)));\n using _ValT = typename iterator_traits<_ForwardIterator>::value_type;\n \n #if __glibcxx_raw_memory_algorithms >= 202411L // >= C++26\n if consteval {\n \treturn std::__do_uninit_copy(__first, __last, __result);\n@@ -285,16 +285,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n #endif\n if constexpr (!__is_trivially_constructible(_ValT, decltype(*__first)))\n \treturn std::__do_uninit_copy(__first, __last, __result);\n else if constexpr (__memcpyable<_Dest, _Src>::__value)\n \t{\n-\t ptrdiff_t __n = __last - __first;\n+\t ptrdiff_t __n\n+\t = std::__miter_base(std::__niter_base(__last))\n+\t - std::__miter_base(std::__niter_base(__first));\n \t if (__n > 0) [[__likely__]]\n \t {\n \t using _ValT = typename remove_pointer<_Src>::type;\n \t __builtin_memcpy(std::__niter_base(__result),\n-\t\t\t std::__niter_base(__first),\n+\t\t\t std::__miter_base(std::__niter_base(__first)),\n \t\t\t __n * sizeof(_ValT));\n \t __result += __n;\n \t }\n \t return __result;\n \t}\ndiff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/121789.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/121789.cc\nnew file mode 100644\nindex 00000000000..7ac8cf6496f\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/121789.cc\n@@ -0,0 +1,37 @@\n+// Copyright (C) 2025-2026 Free Software Foundation, Inc.\n+//\n+// This file is part of the GNU ISO C++ Library. This library is free\n+// software; you can redistribute it and/or modify it under the\n+// terms of the GNU General Public License as published by the\n+// Free Software Foundation; either version 3, or (at your option)\n+// any later version.\n+\n+// This library is distributed in the hope that it will be useful,\n+// but WITHOUT ANY WARRANTY; without even the implied warranty of\n+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+// GNU General Public License for more details.\n+\n+// You should have received a copy of the GNU General Public License along\n+// with this library; see the file COPYING3. If not see\n+// <http://www.gnu.org/licenses/>.\n+\n+// { dg-options \"-O1 -fdump-tree-optimized\" }\n+// { dg-do compile { target c++17 } }\n+// { dg-final { scan-tree-dump \"memcpy\" \"optimized\" } }\n+\n+// PR libstdc++/121789\n+// std::uninitialized_move_n() and friends don't optimize to memcpy\n+\n+#include <memory>\n+\n+struct T { int x; };\n+\n+void f(T* src, T* dst, unsigned n)\n+{\n+ std::uninitialized_move(src, src + n, dst);\n+}\n+\n+void g(T* src, T* dst, unsigned n)\n+{\n+ std::uninitialized_move_n(src, n, dst);\n+}\n", "prefixes": [] }