This function always returns 1, but gcc misses the optimization:

int foo(unsigned char x)
{
  return (x+1) != 0;
}

fold-const.c converts the comparison to "x != -1", but that's it. 
shorten_compare() in c-common.c would optimize it, but it doesn't get called. 
fold-const.c has similar code on lines approx. 9307..9454 but is less general
(and uglier) than shorten_compare() and misses this case.  tree-vrp.c says x is
varying and doesn't help out either.

An example of this construct is line 527 of libmudflap/mf-runtime.c

        if (*optstr+1)

That looks like a buglet, by the way.


-- 
           Summary: Missed optimization of comparison with 'limited range'
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: trt at acm dot org
  GCC host triplet: i686-pc-linux-gnu


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

Reply via email to