[fpc-pascal] FPC 2.7.1 | ARMHF/ARMV6 | Optimization breaks my code at -O2

Nico Erfurth fpc at erfurth.eu
Mon May 27 10:05:59 CEST 2013

On 27.05.13 09:42, Bruce Tulloch wrote:
> What are the optimizations made between -O1 and -O2 on this target?
> Are optimizations at this level materially different when comparing ARM
> to x86 output targets?
> I ask because enabling -O2 breaks my code on ARM but runs fine all the
> way up to -O3 on x86.
> It's no doubt something I'm doing wrong which -O2 is exposing so I
> thought I'd ask if anyone can suggest what types of error are likely
> with building with -O2.
> Prima facie is looks like the object reference ("this" accessed via
> register r0) is corrupt when execution enters this TACTOR_UPDATE (via an
> Inherited call). The disassembly, cpu dump and "this reference" below
> show this but it's not clear to me why or how.

You're misinterpreting the GDB-Output.

While "this" will be in r0 when the method is entered, it gets MOVed to
r4 in the third instruction. Later on r0 is used for many other things.
But "this" is always accessed via r4 (or a mov r0, r4). When you dumped
the registers your PC was somewhere inside the function, not at the
beginning, so you don't have direct access to the incoming values anymore.

It would be helpful if you could do an compilerrun with -alnr for -O2
and -O3 and then show the two versions of that function. Please open a
bugreport for that at http://bugs.freepascal.org/


More information about the fpc-pascal mailing list