This is an archive of the discontinued LLVM Phabricator instance.

Function-relative jump-table encoding
Needs ReviewPublic

Authored by joerg on Oct 26 2016, 5:08 PM.

Details

Reviewers
nadav
Summary

This patch is a work-in-progress base for solving D23250 and the jump-table handling on PPC64. It contains two parts:

  1. A FUNCBASE ISD node that the target should turn into an appropriate address expression. The x86 implementation is provided.
  2. A set of three different jump-table encodings, using different sizes for the delta. Since the value range is limited by the function size, the 32bit encoding works well for large code models as long as functions are still smaller than 4GB. A new peep hole pass could also choose the correct encoding on a per-function base.

I'd like some comments on the general direction of the patch. If someone with a bit familiarity of PPC wants to provide the ISD hook, it would be appreciated. I have no idea how to implement the peep hole pass right now. For 32bit x86, the PIC version results in a slightly more complex instruction, i.e. before it was:

movl    .LJTI0_0@GOTOFF(%eax,%ecx,4), %edx
addl    %eax, %edx

Afterward it is:

movl    .LJTI0_0@GOTOFF(%eax,%ecx,4), %edx
leal    .L0$fb(%edx,%eax), %edx

On 64bit x86, it adds a full instruction because the rip-relative addressing can't fold the offset addition into a single lea. The difference between the different encoding versions would be movl/movslq vs movsbl/movsbq vs movswl/movswq.

Diff Detail

Repository
rL LLVM

Event Timeline

joerg updated this revision to Diff 75969.Oct 26 2016, 5:08 PM
joerg retitled this revision from to Function-relative jump-table encoding.
joerg updated this object.
joerg set the repository for this revision to rL LLVM.
joerg added subscribers: llvm-commits, artagnon.
joerg added a reviewer: nadav.Oct 29 2016, 1:02 PM
joerg added a comment.Oct 29 2016, 1:04 PM

I think I can implement the selection of the jump table encoding as fixup pass on x86. The biggest concern here is that at least for x86_64, the funcbase-difference jump table encodings require one more register. For 32bit mode, that's not a concern as the address computation can be folded with lea into a single operation. So being able to use 16bit encodings for the jump table would imply an additional scratch register to be used, even if the function turns out to be too large. I'm not sure how much that really matters though.