From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 662043858CDA; Fri, 12 May 2023 02:30:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 662043858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683858620; bh=zphaqNLXKUBdf71JRqDOellFG3YXliMfzPKEFoOWbgc=; h=From:To:Subject:Date:From; b=BWZUS0wZibnBK39PRyq/oAYLb1yYVnpIFPJFRikEhr8FJZkw2TdAElaVWnf2NS1Yh ICA+M1Mr0U7PnHPORTepvkdjsPNibi3qt/VE0sap2IS9GUifuZzeMblLu7R1woc6VR kTLlZi25kBnij7DPBC2yA6uPtipDMX84bDBGgwEc= From: "yinyuefengyi at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109821] New: vect: Different output with -O2 -ftree-loop-vectorize compared to -O2 Date: Fri, 12 May 2023 02:30:20 +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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yinyuefengyi 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109821 Bug ID: 109821 Summary: vect: Different output with -O2 -ftree-loop-vectorize compared to -O2 Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: yinyuefengyi at gmail dot com Target Milestone: --- For this test code, it aims to generate special patterns different with mem= cpy or memmove, it generates different results with -O2 -ftree-loop-vectorize compared to -O2, is this a bug of vectorizer that lack of checking the gap = of op-src should be larger than vector mode size (here only do vectorize if op= - src > 16)? copy.cpp: #include #include #include #define UNALIGNED_LOAD64(_p) (*reinterpret_cast(_p)) #define UNALIGNED_STORE64(_p, _val) (*reinterpret_cast(_p) =3D (_val)) __attribute__((__noinline__)) static void IncrementalCopyFastPath(const char* src, char* op, int len) { while (op - src < 8) { UNALIGNED_STORE64(op, UNALIGNED_LOAD64(src)); len -=3D op - src; op +=3D op - src; } while (len > 0) { UNALIGNED_STORE64(op, UNALIGNED_LOAD64(src)); src +=3D 8; op +=3D 8; len -=3D 8; } } int main () { char src[] =3D "123456789abcdefghijklmnopqrstu"; char *op =3D src+12; char * dst =3D op; IncrementalCopyFastPath (src, op, 36); int i =3D 0; while (i < 36) {printf("%x ", *(dst+i)), i++;} printf("\n"); return 0; } $ gcc copy.cpp -O2 -o a.out.good $ ./a.out.good 30 31 32 33 34 35 36 37 38 39 61 62 30 31 32 33 34 35 36 37 38 39 61 62 30 = 31 32 33 34 35 36 37 38 39 61 62 $ gcc copy.cpp -O2 -ftree-loop-vectorize -o a.out.bad $ ./a.out.bad 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 34 35 36 37 38 39 61 62 63 = 64 65 66 73 74 75 76 38 39 61 62 gimple after t.vect: IncrementalCopyFastPath.constprop (const char * src, char * op) { ... [local count: 118111600]: _4 =3D src_8(D) + 8; if (_4 !=3D op_9(D)) // <=3D the check should be op_9 > src_8 + 16 he= re? goto ; [80.00%] else goto ; [20.00%] ... }=