public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/105198] [11/12 Regression] Wrong code for C loop (GCC 12 -O2, GCC 11 -O3) Date: Fri, 08 Apr 2022 10:55:26 +0000 [thread overview] Message-ID: <bug-105198-4-FbpttyrxfN@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-105198-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105198 --- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- So before pcom we have <bb 2> [local count: 114863530]: j_29 = k_28(D) + -1; _1 = (long unsigned int) j_29; _2 = _1 * 4; _3 = x_30(D) + _2; _4 = *_3; _5 = _4 + 1; *_3 = _5; if (j_29 > 0) goto <bb 11>; [94.50%] <bb 11> [local count: 108546036]: <bb 3> [local count: 1014686026]: # j_40 = PHI <j_34(12), j_29(11)> # tmp_39 = PHI <_17(12), _4(11)> _6 = (long unsigned int) j_40; _7 = _6 * 4; _8 = x_30(D) + _7; _9 = *_8; _11 = j_29 - j_40; _12 = n_33(D) - _11; if (_9 < _12) goto <bb 14>; [5.50%] else goto <bb 4>; [94.50%] and pcom replaces the _9 load like the following: <bb 3> [local count: 1014686026]: # j_40 = PHI <j_34(12), j_29(11)> # D__lsm0.5_25 = PHI <D__lsm0.5_18(12), _4(11)> tmp_39 = D__lsm0.5_25; _6 = (long unsigned int) j_40; _7 = _6 * 4; _8 = x_30(D) + _7; _9 = D__lsm0.5_25; _11 = j_29 - j_40; _12 = n_33(D) - _11; if (_9 < _12) goto <bb 14>; [5.50%] else goto <bb 4>; [94.50%] but that fails to realize that while _4 loads from the same address, the *_3 = _5 store clobbers the value. So with pcom applied we exit the loop immediately at the x[j] < n - (k - 1 -j)) test because we use the wrong loop entry value for x[j]. It somehow gets derailed to use 'tmp' here (it doesn't actually even analyze the load/store in BB2). So it's probably wrong in determining Store-loads chain 0x3410a90 max distance 1, may reuse first inits _4 references: *_15 (id 2, write) offset -1 distance 0 looparound ref in statement tmp_39 = PHI <_17(12), _4(11)> distance 1 *_8 (id 0) offset 0 distance 1 in particular identifying the looparound ref which is only partly a looparund ref (the initial value isn't). Indeed, prepare_initializers_chain simply does /* If we have replaced some looparound phi nodes, use their initializers instead of creating our own. */ FOR_EACH_VEC_ELT (chain->refs, i, laref) { if (gimple_code (laref->stmt) != GIMPLE_PHI) continue; gcc_assert (laref->distance > 0); chain->inits[n - laref->distance] = PHI_ARG_DEF_FROM_EDGE (laref->stmt, entry); } which would be OK, but find_looparound_phi simply looks at the def of the loop entry value and matches it up with the chain, not considering intermediate clobbering stmts.
next prev parent reply other threads:[~2022-04-08 10:55 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-07 17:02 [Bug middle-end/105198] New: " tomas.kalibera at gmail dot com 2022-04-08 8:32 ` [Bug tree-optimization/105198] [11/12 Regression] " rguenth at gcc dot gnu.org 2022-04-08 8:45 ` jakub at gcc dot gnu.org 2022-04-08 9:04 ` rguenth at gcc dot gnu.org 2022-04-08 9:12 ` rguenth at gcc dot gnu.org 2022-04-08 10:55 ` rguenth at gcc dot gnu.org [this message] 2022-04-08 12:10 ` [Bug tree-optimization/105198] [9/10/11/12 " rguenth at gcc dot gnu.org 2022-04-08 12:18 ` cvs-commit at gcc dot gnu.org 2022-04-08 12:20 ` [Bug tree-optimization/105198] [9/10/11 " rguenth at gcc dot gnu.org 2022-04-08 13:00 ` cvs-commit at gcc dot gnu.org 2022-04-08 13:00 ` [Bug tree-optimization/105198] [9/10 " rguenth at gcc dot gnu.org 2022-04-08 17:06 ` tomas.kalibera at gmail dot com 2022-05-06 12:47 ` cvs-commit at gcc dot gnu.org 2022-05-27 9:53 ` [Bug tree-optimization/105198] [9 " 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-105198-4-FbpttyrxfN@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).