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: A question about MAX_EXPR


On Mon, Aug 23, 2010 at 02:46:21PM +0300, Revital1 Eres wrote:
> I'm compiling the following test with GCC 4.6.0 and I do not see that
> MAX_EXPR is generated for (num)<0)?0:(num).
> With GCC 4.3.2 it is generated OK in original dump (both compilation were
> made with -O3).  Is there a flag I should use to generate MAX_EXPR
> with GCC 4.6.0?
> 
> Thanks,
> Revital
> 
> #define TEST(num) (unsigned char)(((num)>0xFF)?0xff:(((num)<0)?0:(num)))
> 
> int foo(const unsigned char *tmp, int i, int val)
> {
>     return TEST(tmp[i] + val);
> }

There are two issues here:
1) the (completely unnecessary here) narrowing cast to unsigned char
   This prevents fold_cond_expr_with_comparison from being called, as
   the arguments aren't equal.  One is
   ((int)tmp[i]) + val, the other is tmp[i] + (unsigned char)val.
   Unfortunately even fold_converting the comparison operand
   to (unsigned char) doesn't yield something that would be
   operand_equal_for_comparison_p.
2) without the unnecessary cast, MAX_EXPR is generated, but MIN_EXPR
   around it is not.  The problem is that the argument is not the same,
   (it is the same as TREE_OPERAND (max_expr, 0)).

	Jakub


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