http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28685
--- Comment #20 from Uros Bizjak <ubizjak at gmail dot com> 2012-04-22 12:42:07
UTC ---
(In reply to comment #19)
> int test (int a, int b)
> {
> int lt = a + b < 0;
> int eq = a + b == 0;
> if (lt)
> return 1;
> return eq;
> }
Actually, here ce1 pass steps on cse2 pass. ce1 pass flattens jump-over with a
conditional set. cse2 pass doesn't CSE jumpless blocks (see
cse_condition_code_reg), claiming that:
/* Look for blocks which end with a conditional jump based on a
condition code register. Then look for the instruction which
sets the condition code register. Then look through the
successor blocks for instructions which set the condition
code register to the same value. There are other possible
uses of the condition code register, but these are by far the
most common and the ones which we are most likely to be able
to optimize. */
Changing the source to:
int test (int a, int b)
{
int lt = a + b < 0;
int eq = a + b == 0;
if (lt)
return 15;
return eq;
}
yields one compare (the one in add insn):
test:
addl %esi, %edi
movl $15, %eax
js .L2
sete %al
movzbl %al, %eax
.L2:
rep
ret