Sign in Join

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

Mailing lists / fpc-devel / 2020-08

Question about internal compiler functions

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

J. Gareth Moreton

Hi everyone,

I've found a pretty big optimisation that benefits most ARM platforms, including AArch64, but I'm getting a few random test failures. My investigations suggest that functions like "fpc_chararray_to_unicodestr" and other string conversion routines are not being optimised properly (they're raising Runtime Error 216, which generally implies a fatal exception). For aarch64 in particular, which unit contains the source code or implementation for these functions? I know it's something internal because the disassembly of the actual tests show either no differences with the trunk, or optimisations that manual analysis suggest are correct. I ask for particular units so I can analyse the disassembly, and I rather cut down on the number of megabyte-sized assembly dumps to check!

Gareth aka. Kit

Reply by email

J. Gareth Moreton

Thanks Jonas - I'll see if I can pinpoint it now.

Gareth aka. Kit

On Sun 23/08/20 13:09 , Jonas Maebe via fpc-devel sent:

Show quoted text 31 lines
On 23/08/2020 12:48, J. Gareth Moreton via fpc-devel wrote: > I've found a pretty big optimisation that benefits most ARM platforms, including AArch64, but I'm getting a few random test failures. My investigations suggest that functions like "fpc_chararray_to_unicodestr" and > other string conversion routines are not being optimised properly (they're raising Runtime Error 216, which generally implies a fatal exception). For aarch64 in particular, which unit contains the source code or > implementation for these functions? They're in the system unit (for all platforms). Jonas _______________________________________________ fpc-devel maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

J. Gareth Moreton

That saved me so much work! I found the incorrect code - thanks Jonas!

Trunk:

...
mov x0,x22
bl SYSTEM_$$_NEWUNICODESTRING$INT64$$POINTER
mov x23,x0
lsl x2,x22,#1
mov x1,x23
cbnz x20,.Lj3808
adrp x20,:got:FPC_EMPTYCHAR
ldr x20,[x20, :got_lo12:FPC_EMPTYCHAR]
.Lj3808:
add x0,x20,x21,lsl #1
bl SYSTEM_$$_MOVE$formal$formal$INT64
stur x22,[x23, #-8]
...

Faulty optimisation:

...
mov x0,x22
bl SYSTEM_$$_NEWUNICODESTRING$INT64$$POINTER

        // mov x23,0 gets removed because the optimiser thinks x23 is no longer in use
	lsl	x2,x22,#1
	mov	x1,x0 (*) <-- x0 changed to x23
	cbnz	x20,.Lj3808
	adrp	x20,:got:FPC_EMPTYCHAR
	ldr	x20,[x20, :got_lo12:FPC_EMPTYCHAR]

.Lj3808:
add x0,x20,x21,lsl #1
bl SYSTEM_$$_MOVE$formal$formal$INT64
stur x22,[x23, #-8] <-- x23 is still in use (ERROR!) ...

Now I just have to work out why the peephole optimiser thinks x23 is no longer in use after it changes (*), and why it hasn't caused a more obvious failure elsewhere.

Gareth aka. Kit

On Sun 23/08/20 12:09 , "J. Gareth Moreton via fpc-devel" sent:

Show quoted text 81 lines
Thanks Jonas - I'll see if I can pinpoint it now. Gareth aka. Kit On Sun 23/08/20 13:09 , Jonas Maebe via fpc-devel sent: > On 23/08/2020 12:48, J. Gareth Moreton via fpc-devel wrote: > > > I've found a pretty big optimisation that > benefits most ARM platforms, including AArch64, but I'm getting a few > random test failures. My investigations suggest that functions like > "fpc_chararray_to_unicodestr" and > > other string conversion routines are not being > optimised properly (they're raising Runtime Error 216, which generally > implies a fatal exception). For aarch64 in particular, which unit contains > the source code or > > implementation for these functions? > > > > They're in the system unit (for all platforms). > > > > > > Jonas > > _______________________________________________ > > fpc-devel maillist - > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > > > > > _______________________________________________ fpc-devel maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Jonas Maebe
to J. Gareth Moreton: I've found a pretty big optimisation that benefits most ARM platforms, including AArch64,…
J. Gareth Moreton wrote
I've found a pretty big optimisation that benefits most ARM platforms, including AArch64, but I'm getting a few random test failures. My investigations suggest that functions like "fpc_chararray_to_unicodestr" and other string conversion routines are not being optimised properly (they're raising Runtime Error 216, which generally implies a fatal exception). For aarch64 in particular, which unit contains the source code or implementation for these functions?

They're in the system unit (for all platforms).

Jonas

Reply by email