This is the mail archive of the gcc-patches@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: [PATCH] Fix overzealous folding


> The test-case you posed is, if I understand correctly, not on point.
> It's showing that we take advantage of the limited range of an enum to
> optimize away a check.  That's great.

You apparently didn't compile it...  Not only is the check not eliminated in 
either case at -O2, but the code is worse with the enumeration type, thus 
showing that the equivalence principle doesn't hold in this simple case.

> The principle I am arguing for is that an ENUMERAL_TYPE is no different
> from an INTEGER_TYPE *with the same range*.  In your case, "int" and
> "my_enum" have different ranges.

Then it's purely a theoritical principle and I'm not sure it's worth arguing 
for: INTEGER_TYPEs have maximal range in C++ whereas ENUMERAL_TYPEs don't.

So you would need something like:

typedef enum { FIRST = -2147483648, SECOND = 2, THIRD = 2147483647 } my_enum;

#else

typedef int my_enum;

#define FIRST  -2147483648
#define SECOND 2
#define THIRD  2147483647

to be able to apply it.

-- 
Eric Botcazou


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