From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7A1A93858D37; Thu, 31 Aug 2023 11:48:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A1A93858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693482510; bh=v3sdwjh4M+ijXeInVAovnocRiIzHtNl5KPais5UgoQs=; h=From:To:Subject:Date:From; b=QRoiaGRV4MFd/wqOidw24pmi6fkpOWrzyTnYrl2EsTUrQYT32k01AtmnB1L1BkDCU 6VFEjjR46dLQXpLDN/gaeCT4TB9iD9xRgEFtGrRseO/9p7tOdrph4Pp549PoCC8TtK QDRS2oHFPmjDM0K4R5id15z3o3DhRv2/Pcc44F2w= From: "kristerw at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111257] New: new signed overflow after vectorizer Date: Thu, 31 Aug 2023 11:48:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kristerw at gcc dot gnu.org 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=3D111257 Bug ID: 111257 Summary: new signed overflow after vectorizer Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: kristerw at gcc dot gnu.org Target Milestone: --- The vectorizer is not removing the original scalar calculations, and they m= ay overflow after vectorization. This can be seen with int a[8]; void foo(void) { for (int i =3D 0; i < 8; i++) a[i] =3D a[i] + 5; } The IR for the loop before vectorization looks like [local count: 954449104]: # i_10 =3D PHI # ivtmp_4 =3D PHI _1 =3D a[i_10]; _2 =3D _1 + 5; a[i_10] =3D _2; i_7 =3D i_10 + 1; ivtmp_3 =3D ivtmp_4 - 1; if (ivtmp_3 !=3D 0) goto ; [87.50%] else goto ; [12.50%] [local count: 835156385]: goto ; [100.00%] and it is vectorized to [local count: 238585440]: # i_10 =3D PHI # ivtmp_4 =3D PHI # vectp_a.4_9 =3D PHI # vectp_a.8_16 =3D PHI # ivtmp_19 =3D PHI vect__1.6_13 =3D MEM [(int *)vectp_a.4_9]; _1 =3D a[i_10]; vect__2.7_15 =3D vect__1.6_13 + { 5, 5, 5, 5 }; _2 =3D _1 + 5; MEM [(int *)vectp_a.8_16] =3D vect__2.7_15; i_7 =3D i_10 + 1; ivtmp_3 =3D ivtmp_4 - 1; vectp_a.4_8 =3D vectp_a.4_9 + 16; vectp_a.8_17 =3D vectp_a.8_16 + 16; ivtmp_20 =3D ivtmp_19 + 1; if (ivtmp_20 < 2) goto ; [50.00%] else goto ; [50.00%] [local count: 119292723]: goto ; [100.00%] This vectorized loop still read _1 from a[i_10] and adds 5 to it, so the se= cond loop iteration will add 5 to the value of a[1]. But the first iteration has already added 5 to a[1], so we are now doing a different calculation compar= ed to the original loop, and this can overflow even if the original did not.=