Bug 24990 - fold should convert ~a != C to a != ~C where C is a constant
Summary: fold should convert ~a != C to a != ~C where C is a constant
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: 4.2.0
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: missed-optimization, patch, TREE
Depends on:
Blocks: 19986 18908
  Show dependency treegraph
 
Reported: 2005-11-22 20:56 UTC by Andrew Pinski
Modified: 2023-12-31 17:27 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-11-22 20:58:29


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-11-22 20:56:05 UTC
Take the following couple functions:
int f(int a)
{
  return (~a) != 0;
}

int f1(int a)
{
  return a != (~0);
}

int f2(int a)
{
  return (~a) != 1;
}

int f3(int a)
{
  return a != (~1);
}

f and f1 should be the same.  Likewise for f2 and f3.
Comment 1 Andrew Pinski 2005-11-22 20:58:29 UTC
This is done on the RTL level already but would be nice to get it at the TREE level so that it can fix if we have bools which is PR 18908.

Mine working on a patch.
Comment 2 Andrew Pinski 2005-11-22 21:12:03 UTC
== and != should be handled the same.  Change the summary to reflect the testcase in comment #0.
Comment 3 Andrew Pinski 2005-11-24 21:19:10 UTC
Patch posted.
Comment 4 Andrew Pinski 2005-11-25 04:55:02 UTC
Subject: Bug 24990

Author: pinskia
Date: Fri Nov 25 04:54:59 2005
New Revision: 107487

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107487
Log:
2005-11-25  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/24990
        * fold-const.c (fold_binary): Fold (~a) == C to a == ~C
        for C being INTEGER_CST.  Likewise for !=.
2005-11-24  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/24990
        * tree-ssa/pr24990-1.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr24990-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Andrew Pinski 2005-11-25 04:55:24 UTC
Fixed.