public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* A question about MAX_EXPR
@ 2010-08-23 13:52 Revital1 Eres
  2010-08-23 14:44 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Revital1 Eres @ 2010-08-23 13:52 UTC (permalink / raw)
  To: gcc


Hello,

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);
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: A question about MAX_EXPR
  2010-08-23 13:52 A question about MAX_EXPR Revital1 Eres
@ 2010-08-23 14:44 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2010-08-23 14:44 UTC (permalink / raw)
  To: Revital1 Eres; +Cc: gcc

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-23 13:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-23 13:52 A question about MAX_EXPR Revital1 Eres
2010-08-23 14:44 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).