public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "kristerw at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-111257-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111257 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 may overflow after vectorization. This can be seen with int a[8]; void foo(void) { for (int i = 0; i < 8; i++) a[i] = a[i] + 5; } The IR for the loop before vectorization looks like <bb 3> [local count: 954449104]: # i_10 = PHI <i_7(5), 0(2)> # ivtmp_4 = PHI <ivtmp_3(5), 8(2)> _1 = a[i_10]; _2 = _1 + 5; a[i_10] = _2; i_7 = i_10 + 1; ivtmp_3 = ivtmp_4 - 1; if (ivtmp_3 != 0) goto <bb 5>; [87.50%] else goto <bb 4>; [12.50%] <bb 5> [local count: 835156385]: goto <bb 3>; [100.00%] and it is vectorized to <bb 3> [local count: 238585440]: # i_10 = PHI <i_7(5), 0(2)> # ivtmp_4 = PHI <ivtmp_3(5), 8(2)> # vectp_a.4_9 = PHI <vectp_a.4_8(5), &a(2)> # vectp_a.8_16 = PHI <vectp_a.8_17(5), &a(2)> # ivtmp_19 = PHI <ivtmp_20(5), 0(2)> vect__1.6_13 = MEM <vector(4) int> [(int *)vectp_a.4_9]; _1 = a[i_10]; vect__2.7_15 = vect__1.6_13 + { 5, 5, 5, 5 }; _2 = _1 + 5; MEM <vector(4) int> [(int *)vectp_a.8_16] = vect__2.7_15; i_7 = i_10 + 1; ivtmp_3 = ivtmp_4 - 1; vectp_a.4_8 = vectp_a.4_9 + 16; vectp_a.8_17 = vectp_a.8_16 + 16; ivtmp_20 = ivtmp_19 + 1; if (ivtmp_20 < 2) goto <bb 5>; [50.00%] else goto <bb 4>; [50.00%] <bb 5> [local count: 119292723]: goto <bb 3>; [100.00%] This vectorized loop still read _1 from a[i_10] and adds 5 to it, so the second 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 compared to the original loop, and this can overflow even if the original did not.
next reply other threads:[~2023-08-31 11:48 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-08-31 11:48 kristerw at gcc dot gnu.org [this message] 2023-08-31 13:22 ` [Bug tree-optimization/111257] " rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-111257-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).