Missing if optimization
Andrew Pinski
pinskia@physics.uc.edu
Thu Sep 9 05:49:00 GMT 2004
On Sep 8, 2004, at 10:19 PM, Uros Bizjak wrote:
> Hello!
>
> The if optimization, which produces quite optimized code for integer
> case is missing for floatin-point compares.
>
> This code:
>
> int test(int a) {
> return a == 0 ? 0 : (a > 0 ? 1 : -1);
> }
>
> produces (with -O2 -fomit-frame-pointer):
>
> test:
> xorl %eax, %eax
> cmpl $0, 4(%esp)
> je .L4
> setg %al
> movzbl %al, %eax
> leal -1(%eax,%eax), %eax
> .L4:
> ret
>
> However, fp compares:
>
> double testf(double a) {
> return a == 0.0 ? 0.0 : (a > 0.0 ? 1.0 : -1.0);
> }
On PPC we get only one compare:
(This is with a month old compiler):
_testf:
lis r2,ha16(LC0)
la r2,lo16(LC0)(r2)
lfd f0,0(r2)
fcmpu cr7,f1,f0 <-- the one and only compare
beq- cr7,L4
lis r2,ha16(LC1)
la r2,lo16(LC1)(r2)
lfd f0,0(r2)
bgt- cr7,L8
L4:
fmr f1,f0
blr
L8:
lis r2,ha16(LC2)
la r2,lo16(LC2)(r2)
lfd f0,0(r2)
fmr f1,f0
blr
Thanks,
Andrew Pinski
More information about the Gcc
mailing list