public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dberlin at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/23588] New: CCP not fully propagating constants
Date: Sat, 27 Aug 2005 03:31:00 -0000	[thread overview]
Message-ID: <20050827022854.23588.dberlin@gcc.gnu.org> (raw)

Consider
int main(int a, int b, int c, int d)
{
  d = -1;
  int e = (a | b) | (c | d);
  int f = (c | a) | (b | d);
 return e | f;
}

Because d == -1, the whole thing folds to return -1;

CCP doesn't do this however.
It takes:
  # BLOCK 0
  # PRED: ENTRY (fallthru)
  d_1 = -1;
  D.1285_4 = a_2 | b_3;
  D.1286_6 = c_5 | d_1;
  e_7 = D.1285_4 | D.1286_6;
  D.1287_8 = c_5 | a_2;
  D.1288_9 = b_3 | d_1;
  f_10 = D.1287_8 | D.1288_9;
  D.1289_12 = e_7 | f_10;
  return D.1289_12;
  # SUCC: EXIT

and turns it into
main (a, b, c, d)
{
  int f;
  int e;
  int D.1289;
  int D.1288;
  int D.1287;
  int D.1286;
  int D.1285;

  # BLOCK 0
  # PRED: ENTRY (fallthru,exec)
  d_1 = -1;
  D.1285_4 = a_2 | b_3;
  D.1286_6 = -1;
  e_7 = D.1285_4 | D.1286_6;
  D.1287_8 = c_5 | a_2;
  D.1288_9 = -1;
  f_10 = D.1287_8 | D.1288_9;
  D.1289_12 = e_7 | f_10;
  return D.1289_12;
  # SUCC: EXIT

}

(note that it's not actually following the use edges, or it would have folded it
all the way)

The propagation looks broken:

;; Function main (main)

Immediate_uses:

d_1 : -->2 uses.
D.1288_9 = b_3 | d_1;
D.1286_6 = c_5 | d_1;

a_2 : -->2 uses.
D.1287_8 = c_5 | a_2;
D.1285_4 = a_2 | b_3;

b_3 : -->2 uses.
D.1288_9 = b_3 | d_1;
D.1285_4 = a_2 | b_3;

D.1285_4 : --> single use.
e_7 = D.1285_4 | D.1286_6;

c_5 : -->2 uses.
D.1287_8 = c_5 | a_2;
D.1286_6 = c_5 | d_1;

D.1286_6 : --> single use.
e_7 = D.1285_4 | D.1286_6;

e_7 : --> single use.
D.1289_12 = e_7 | f_10;

D.1287_8 : --> single use.
f_10 = D.1287_8 | D.1288_9;

D.1288_9 : --> single use.
f_10 = D.1287_8 | D.1288_9;

f_10 : --> single use.
D.1289_12 = e_7 | f_10;

D.1289_12 : --> single use.
return D.1289_12;

<retval>_13 : --> no uses.

Simulating block 0

Visiting statement:
d_1 = -1;

Lattice value changed to CONSTANT -1.  Adding SSA edges to worklist.

Substituing values and folding statements

Folded statement: D.1286_6 = c_5 | d_1;
            into: D.1286_6 = -1;

Folded statement: D.1288_9 = b_3 | d_1;
            into: D.1288_9 = -1;

Constants propagated:      2
Copies propagated:         0
Predicates folded:         0


If it had actually added the ssa edges to the worklist, followed them, and
folded the statements containing the new constant, it would have gotten the
right answer.

-- 
           Summary: CCP not fully propagating constants
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dberlin at gcc dot gnu dot org
                CC: dnovillo at gcc dot gnu dot org,gcc-bugs at gcc dot gnu
                    dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23588


             reply	other threads:[~2005-08-27  2:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-27  3:31 dberlin at gcc dot gnu dot org [this message]
2005-08-27  3:31 ` [Bug tree-optimization/23588] " pinskia at gcc dot gnu dot org
2005-09-07  3:46 ` pinskia at gcc dot gnu dot org
2005-09-07  3:51 ` pinskia at gcc dot gnu dot org
2005-09-07  4:28 ` pinskia at gcc dot gnu dot org
2005-09-07 13:36 ` dberlin at dberlin dot org
2005-09-21 15:02 ` steven at gcc dot gnu dot 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=20050827022854.23588.dberlin@gcc.gnu.org \
    --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).