From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B44B13858020; Thu, 15 Apr 2021 18:06:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B44B13858020 From: "hewillk at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/100104] New: std::transform is 1.5 times faster than std::copy with -O3 Date: Thu, 15 Apr 2021 18:06:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hewillk at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Apr 2021 18:06:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100104 Bug ID: 100104 Summary: std::transform is 1.5 times faster than std::copy with -O3 Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hewillk at gmail dot com Target Milestone: --- Consider: std::vector v1(100, 0); // copy using copy std::vector v2; std::copy(v1.begin(), v1.end(), std::back_inserter(v2)); // copy using transform std::vector v2; std::transform(v1.begin(), v1.end(), std::back_inserter(v2), [](auto x) { return x; }); Those two will generate similar assembly code under -O2, but is very differ= ent under -O3/-Ofast, and transform will be 1.5 times faster than the copy. I d= on=E2=80=99t know if this is a bug since these two represent the same thing, and correct= me if I am wrong. quick-bench with -O2: https://quick-bench.com/q/uKT8QEmPkS1wr153s3P-DRt90eY quick-bench with -O3: https://quick-bench.com/q/syuBCQYVtCoVwT2MRtLT25P-MQI goldbot:=20 https://godbolt.org/z/7ee77cs8W=