Useless conditional branches

2010-03-02 Thread Alain Ketterlin
It looks like gcc sometimes produces "useless" conditional branches. I've found code like this: xor%edx,%edx ; code with no effect on edx (see full code below) test %edx,%edx jne The branch on the last line is never taken. Why does gcc generate such code sequences? Is this pat

Re: Useless conditional branches

2010-03-02 Thread Alain Ketterlin
Andrew Haley wrote: On 03/02/2010 08:55 AM, Alain Ketterlin wrote: It looks like gcc sometimes produces "useless" conditional branches. I've found code like this: xor%edx,%edx ; code with no effect on edx (see full code below) test %edx,%edx jne The branch o

Sub-optimal code

2010-03-18 Thread Alain Ketterlin
I've reported here recently about gcc producing conditional branches with static outcome. I've finally managed to produce a simple self-contained example. Here it is: int f() { static int LSW=-1; double x=0.987654321; unsigned char ix = *((char *)&x); if(ix==0xdd || ix==0x3f)

Irreducible loops in generated code

2010-08-18 Thread Alain Ketterlin
I'm working on decompiling x86-64 binary programs, using branches to rebuild a control-flow graph and looking for loops. I've found a significant number of irreducible loops in gcc-produced code (irreducible loops are loops with more than one entry point), especially in -O3 optimized binaries

Re: Irreducible loops in generated code

2010-08-18 Thread Alain Ketterlin
On 18/08/2010 12:37, Steven Bosscher wrote: On Wed, Aug 18, 2010 at 11:53 AM, Alain Ketterlin wrote: My question is: where do these irreducible loops come from? Which optimization pass leads to irreducible regions? Thanks in advance for any pointer. Questions right back at you: What

jump after return

2010-11-11 Thread Alain Ketterlin
When compiling at -O2 and -O3 optimization, I've found several instances of routines ending with: retq jmp with no branch pointing to the jmp instruction. Is there any specific reason for such code? Is there a way to avoid this? This is gcc 4.4.5, as installed on Ubuntu 10.10, compiling t