public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/54810] New: VRP doesn't handle comparison of narrowing cast like comparison of BIT_AND_EXPR
@ 2012-10-04  9:48 jakub at gcc dot gnu.org
  2012-10-04  9:56 ` [Bug tree-optimization/54810] " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-10-04  9:48 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 54810
           Summary: VRP doesn't handle comparison of narrowing cast like
                    comparison of BIT_AND_EXPR
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jakub@gcc.gnu.org


struct S
{
  unsigned long w;
  void (*u) (void *, unsigned int, unsigned int);
};

struct T;
typedef void (*a_t) (struct T *);
typedef void (*b_t) (struct T *);

struct T
{
  a_t a;
  b_t b;
  struct S c;
  int d, e, f;
};

_Bool fn1 (struct T *, unsigned int);
int fn2 (struct T *, unsigned int, void *, unsigned long);
int fn3 (struct T *, unsigned int, unsigned int *);

static _Bool
foo (struct T *x, unsigned int y, unsigned int z)
{
  unsigned int i;
  for (i = 0; i < z; i++)
    if (!fn1 (x, y + i))
      return 0;
  return 1;
}

int
bar (struct T *x, unsigned int y, void *z, unsigned long s)
{
  unsigned long w = x->c.w;
  unsigned long q = s / w;
  unsigned int v;
  int r, i;
  if (s % x->c.w)
    return -22;
  if (y % x->d)
    return -22;
  x->a (x);
  if (foo (x, y, q) || x->f || x->e == 0)
    r = fn2 (x, y, z, s);
  else
    for (i = 0; i < q; i++)
      {
        r = fn3 (x, y + (i * x->d), &v);
        if (r != 0)
          break;

        x->c.u (z + (i * w), v, 0);
      }
  x->b (x);
  return r;
}

reports at -O2 -Wall maybe uninitialized warning.  While generally it is IMHO
an acceptable false positive, especially if foo doesn't get inlined, this
testcase lead to me find out that while we handle
  _7 = _4 & 0xffff;
  if (_7 == 0)
    goto bbX;
by adding ASSERT_EXPRs for _4 (in the _7 != 0 code _4 is known to be non-zero,
in the _7 == 0 code it can e.g. have [0, 0xffff0000] range), we don't handle
  _7 = (unsigned short) _4;
  if (_7 == 0)
    goto bbX;
the same way.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/54810] VRP doesn't handle comparison of narrowing cast like comparison of BIT_AND_EXPR
  2012-10-04  9:48 [Bug tree-optimization/54810] New: VRP doesn't handle comparison of narrowing cast like comparison of BIT_AND_EXPR jakub at gcc dot gnu.org
@ 2012-10-04  9:56 ` jakub at gcc dot gnu.org
  2012-10-04 10:03 ` pinskia at gcc dot gnu.org
  2012-10-05  9:38 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-10-04  9:56 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-10-04
         AssignedTo|unassigned at gcc dot       |jakub at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-10-04 09:55:25 UTC ---
Created attachment 28356
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28356
gcc48-pr54810.patch

Untested patch.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/54810] VRP doesn't handle comparison of narrowing cast like comparison of BIT_AND_EXPR
  2012-10-04  9:48 [Bug tree-optimization/54810] New: VRP doesn't handle comparison of narrowing cast like comparison of BIT_AND_EXPR jakub at gcc dot gnu.org
  2012-10-04  9:56 ` [Bug tree-optimization/54810] " jakub at gcc dot gnu.org
@ 2012-10-04 10:03 ` pinskia at gcc dot gnu.org
  2012-10-05  9:38 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-10-04 10:03 UTC (permalink / raw)
  To: gcc-bugs


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org
           Severity|normal                      |enhancement


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/54810] VRP doesn't handle comparison of narrowing cast like comparison of BIT_AND_EXPR
  2012-10-04  9:48 [Bug tree-optimization/54810] New: VRP doesn't handle comparison of narrowing cast like comparison of BIT_AND_EXPR jakub at gcc dot gnu.org
  2012-10-04  9:56 ` [Bug tree-optimization/54810] " jakub at gcc dot gnu.org
  2012-10-04 10:03 ` pinskia at gcc dot gnu.org
@ 2012-10-05  9:38 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-10-05  9:38 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-10-05 09:37:32 UTC ---
Author: jakub
Date: Fri Oct  5 09:37:25 2012
New Revision: 192115

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192115
Log:
    PR tree-optimization/54810
    * tree-vrp.c (register_edge_assert_for_2): Handle
    NAME = (unsigned) NAME2; if (NAME cmp CST) for
    narrowing casts to unsigned integral type like
    NAME = NAME2 & CST2; if (NAME cmp CST) where CST2
    is the max value of the unsigned integral type.

    * gcc.dg/tree-ssa/vrp85.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/vrp85.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vrp.c


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-10-05  9:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-04  9:48 [Bug tree-optimization/54810] New: VRP doesn't handle comparison of narrowing cast like comparison of BIT_AND_EXPR jakub at gcc dot gnu.org
2012-10-04  9:56 ` [Bug tree-optimization/54810] " jakub at gcc dot gnu.org
2012-10-04 10:03 ` pinskia at gcc dot gnu.org
2012-10-05  9:38 ` jakub at gcc dot gnu.org

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).