public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "amker at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/43174] Teaching SCEV about ADDR_EXPR causes regression
Date: Mon, 17 Aug 2015 09:25:00 -0000	[thread overview]
Message-ID: <bug-43174-4-zMlXE2j5vD@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-43174-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43174

--- Comment #3 from amker at gcc dot gnu.org ---
Note for the three levels of loop example, GCC chooses one IV for both j and k
loops, thus generates pretty clean output on x86_64 with O2.  

For the simple example, now gcc can eliminate comparison iv with the address
candidate, and generates below codes:

  <bb 2>:
  ivtmp.18_14 = (unsigned long) &a;
  _10 = &a + 60516;
  _28 = (unsigned long) _10;
  goto <bb 7>;

  <bb 3>:

  <bb 4>:
  # s_18 = PHI <s_9(3), s_19(7)>
  # ivtmp.9_12 = PHI <ivtmp.9_1(3), ivtmp.9_4(7)>
  _22 = (void *) ivtmp.9_12;
  _8 = MEM[base: _22, offset: 0B];
  s_9 = _8 + s_18;
  ivtmp.9_1 = ivtmp.9_12 + 4;
  if (ivtmp.9_1 != _27)
    goto <bb 3>;
  else
    goto <bb 5>;

  <bb 5>:
  # s_17 = PHI <s_9(4)>
  ivtmp.18_15 = ivtmp.18_5 + 492;
  if (ivtmp.18_15 != _28)
    goto <bb 6>;
  else
    goto <bb 8>;

  <bb 6>:

  <bb 7>:
  # s_19 = PHI <s_17(6), 0(2)>
  # ivtmp.18_5 = PHI <ivtmp.18_15(6), ivtmp.18_14(2)>
  ivtmp.9_4 = ivtmp.18_5;
  _29 = ivtmp.18_5 + 492;
  _27 = _29;
  goto <bb 4>;

  <bb 8>:
  # s_16 = PHI <s_17(5)>
  return s_16;

With this, following gimple optimizers are able to CSE the opportunity of
"ivtmp.18_5 + 492".  As a result, optimal code is generated as in optimized
dump:


  <bb 2>:
  ivtmp.18_14 = (unsigned long) &a;
  _28 = (unsigned long) &MEM[(void *)&a + 60516B];
  goto <bb 5>;

  <bb 3>:
  # s_18 = PHI <s_9(3), s_19(5)>
  # ivtmp.9_12 = PHI <ivtmp.9_1(3), ivtmp.18_5(5)>
  _22 = (void *) ivtmp.9_12;
  _8 = MEM[base: _22, offset: 0B];
  s_9 = _8 + s_18;
  ivtmp.9_1 = ivtmp.9_12 + 4;
  if (ivtmp.9_1 != _29)
    goto <bb 3>;
  else
    goto <bb 4>;

  <bb 4>:
  if (_28 != _29)
    goto <bb 5>;
  else
    goto <bb 6>;

  <bb 5>:
  # s_19 = PHI <s_9(4), 0(2)>
  # ivtmp.18_5 = PHI <_29(4), ivtmp.18_14(2)>
  _29 = ivtmp.18_5 + 492;
  goto <bb 3>;

  <bb 6>:
  return s_9;

This in effect is the transformation you wanted in this PR, but I doubt if GCC
can do this if it can't eliminate the inner loop's comparison using ivtmp.9_1
at the first place.

On the other hand, for cases that we can use IV's final value, it maybe likely
for GCC to eliminate the comparison IV.


       reply	other threads:[~2015-08-17  9:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-43174-4@http.gcc.gnu.org/bugzilla/>
2015-08-17  9:25 ` amker at gcc dot gnu.org [this message]
2015-08-17  9:26 ` amker at gcc dot gnu.org
2010-02-25 14:43 [Bug tree-optimization/43174] New: " amonakov at gcc dot gnu dot org
2010-02-25 15:26 ` [Bug tree-optimization/43174] " steven at gcc dot gnu dot org
2010-03-01 17:44 ` amonakov at gcc dot gnu dot org
2010-03-03  9:21 ` rakdver at kam dot mff dot cuni dot cz

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-43174-4-zMlXE2j5vD@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: link
Be 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).