[fpc-devel] Quirk is "IsJumpToLabel"
J. Gareth Moreton
gareth at moreton-family.com
Fri Nov 10 23:53:11 CET 2023
Hi everyone,
I've been developing a new optimisation for x86, and in one situation a
JMP becomes a Jcc. To make sure it's valid, I ensure that
"IsJumpToLabel" returns True before the change is made. All was well in
x86_64-win64 and x86_64-linux, but on i386-linux, I came across a bit of
an anomaly:
jmp _$RTTI$_Ld3(,%eax,4)
It turns out that "IsJumpToLabel" returns true for this construct, which
is not valid for Jcc. _$RTTI$_Ld3 is a jump table stored as a data
structure. The question is though... should this be treated as a jump
to a label?
Currently, my optimisation fails on i386-linux because of
"IsJumpToLabel" returning True on this. I can modify my code so it
makes sure there's no index register, but this feels a bit hacky and
there may be other, unrelated blocks of code that could fall foul of a
similar situation, and I personally feel that "IsJumpToLabel" should
return True only for pure labels. However, such a change will affect
other platforms and I don't yet know what effect that will have.
As a side-node, because of the principle of relocation under x86_64,
jump table access is more complex. The equivalent code for "jmp
_$RTTI$_Ld3(,%eax,4)" on x86_64-win64 is:
leaq .Ld3(%rip),%rdx
movslq (%rdx,%rax,4),%rax
addq %rdx,%rax
jmp *%rax
(The jump table contains relative addresses rather than absolute
addresses, hence the need for "addq %rdx,%rax")
And of course, the JMP instruction is not considered a jump to a label.
Kit
More information about the fpc-devel
mailing list