Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-10

Optimization stops near inline asm

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexander Klenin
the following code:
{$mode objfpc}
var
  a: Integer;
begin
  a := a + 1;
  asm nop end;
end.

generates (under -O2):

movl U_P$PROGRAM_A,%eax
incl %eax
movl %eax,U_P$PROGRAM_A
nop

instead of a single "incl".
removing either "asm" statement OR $mode directive reinstates the optimization (although in the latter case with "incw", of course).

This obviously never matters in practice, but may be a symptom of some more serious problem. Should I file a bug report?

Alexander S. Klenin

Reply by email

Florian Klämpfl
to Alexander Klenin
Alexander Klenin wrote 24 lines
the following code: {$mode objfpc} var a: Integer; begin a := a + 1; asm nop end; end. generates (under -O2): movl U_P$PROGRAM_A,%eax incl %eax movl %eax,U_P$PROGRAM_A nop instead of a single "incl". removing either "asm" statement OR $mode directive reinstates the optimization (although in the latter case with "incw", of course). This obviously never matters in practice, but may be a symptom of some more serious problem. Should I file a bug report?

FPC doesn't do any optimization in procedures containing inline assembler.

Reply by email

Jonas Maebe
to Florian Klämpfl
Florian Klämpfl wrote
FPC doesn't do any optimization in procedures containing inline assembler.

It does. But also assumes that all registers are used in assembler blocks, unless the programmer specifies otherwise. If you change the assembler block into

   asm nop end [];

then the statement will optimized. Otherwise the compiler assumes that the contents of eax may still be used inside the assembler block and hence cannot remove its use.

The fact that the optimization is performed in case the used register is ax instead of eax suggests a small bug.

Jonas

Reply by email

Alexander Klenin
to Jonas Maebe

2011/10/3 Jonas Maebe :

Show quoted text 8 lines
 asm nop end []; then the statement will optimized. Otherwise the compiler assumes that the contents of eax may still be used inside the assembler block and hence cannot remove its use. The fact that the optimization is performed in case the used register is ax instead of eax suggests a small bug.

I see, thanks.

Alexander S. Klenin

Reply by email