[Bug tree-optimization/71558] New: missed optimization for type short, char and floating point types

denis.campredon at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Jun 16 15:08:00 GMT 2016


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

            Bug ID: 71558
           Summary: missed optimization for type short, char and floating
                    point types
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denis.campredon at gmail dot com
  Target Milestone: ---

for the following code gcc should produce the same code for fun and fun2, but
fail for shorts and char with -01 and higher. It also fails for floating types
with -0fast
-----------------
#define optimize(type)          \
type fun(type i, type j)        \
{                               \
  return i + j;                 \
}                               \
type fun2(type i, type j)       \
{                               \
  if (j == 0)                   \
    return i;                   \
  else if (i == 0)              \
    return j;                   \
  else                          \
    return i + j;               \
}


optimize(int);
optimize(char);
optimize(short);
--------------------

For all types the optimization is no longer performed if any type is different
from the other 
--------------------
int fun2(unsigned i, int j)
{
  if (i == 0)
    return j;
  else if (j == 0)
    return i;
  else
    return i + j;
}
--------------------
And if we are testing if both i and j are 0 the optimization is no longer
performed
------------------
int fun2(int i, int j)
{
  if (i == 0 && j == 0)
    return j; //or "return i + j;" or "return 0;" or "return i;"
  if (i == 0)
    return j;
  else if (j == 0)
    return i;
  else
    return i + j;
}
-------------------
It also fails if one replace the addition with a subtraction or a
multiplication (with changed return values.)


More information about the Gcc-bugs mailing list