[Issue 5688] Poor optimization of (long & 1)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 3 17:55:39 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5688
--- Comment #2 from Don <clugdbug at yahoo.com.au> 2011-03-03 17:52:46 PST ---
(In reply to comment #1)
> Interestingly, if the code is written as:
>
> bool foo(long v)
> {
> return (v & 1) == 1;
> }
>
> the code generated is:
>
> mov EAX,4[ESP]
> mov EDX,8[ESP]
> and EAX,1
> xor EDX,EDX
> ret 8
I noticed that. And even though that's better, both uses of EDX are completely
unnecessary.
Changing cgelem.c, elcmp(), around line 3350 to this:
case 8:
- e = el_una(OP64_32,TYlong,e);
+ e->E1 = el_una(OP64_32,TYint,e->E1);
+ e->E2 = el_una(OP64_32,TYint,e->E2);
break;
makes it create optimal code, although that's probably incorrect for 64 bits.
The way elcmp() works looks pretty bizarre to me.
But it's the return ( v & 1); case that is the primary problem.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list