This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: More embarrassing failures to optimize


>>>>> "Z" == Zack Weinberg <zack@codesourcery.com> writes:

Z> I suspect this is the same underlying problem that causes
Z> gcc.c-torture/execute/builtin-constant.c to fail.  This was discussed
Z> at some length in the thread starting at
Z> http://gcc.gnu.org/ml/gcc-patches/2002-11/msg00235.html - it's
Z> nontrivial to fix.

Independently of whether it's related to builtin_constant_p, the fact
that the class containing the direct conversion to bool can be
optimized as desired suggests a different approach for improving
optimization:

Make sure that constant pointer expressions used in boolean contexts
can be optimized as well as constant expressions of type bool.

class Bool1 // optimizable
{
private: const bool val_;
public:
  Bool1 (bool val)     : val_ (val)   {}
  operator bool () const { return val_; }
};

class Bool2 // less optimizable - Why?
{
private: const bool val_;
  struct Conv { int Dummy; };
public:
  Bool2 (bool val)     : val_ (val)   {}
  operator int Conv::* () const { return val_ ? & Conv::Dummy : 0; }
};


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]