[PATCH] D78465: [AArch64][GlobalISel] Split G_GLOBAL_VALUE into ADRP + G_ADD_LOW and optimize.

Amara Emerson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 19 18:08:57 PDT 2020


aemerson created this revision.
aemerson added a reviewer: paquette.
aemerson added a project: LLVM.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls, rovka.

The concept of G_GLOBAL_VALUE is nice and simple, but always using it as the representation for global var addressing until selection time creates some problems in optimizing accesses in certain code/relocation models.

The problem comes from trying to optimize adrp -> add -> load/store sequences in the most common "small" code model. These accesses can be optimized into an adrp -> load with the add offset being folded into the load's immediate field. If we try to keep all global var references as a single generic instruction then by the time we get to the complex operand trying to match these, we end up generating an adrp at the point of use. The real issue here is that we don't have any form of CSE during selection, so the code size will bloat from many redundant adrp's.

This patch custom legalizes small code mode non-GOT G_GLOBALs into target ADRP and a new "target specific generic opcode" G_ADD_LOW. We also teach the localizer to localize these instructions via the custom hook that was added recently. Finally, the complex pattern for indexed loads/stores is extended to try to fold these G_ADD_LOW instructions into the load immediate.

On -O0 CTMark internal, we see a 0.8% geomean code size improvement. We should also see some minor performance improvements too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78465

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64InstrGISel.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
  llvm/lib/Target/AArch64/AArch64LegalizerInfo.cpp
  llvm/lib/Target/AArch64/AArch64LegalizerInfo.h
  llvm/test/CodeGen/AArch64/GlobalISel/call-translator-variadic-musttail.ll
  llvm/test/CodeGen/AArch64/GlobalISel/legalize-blockaddress.mir
  llvm/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir
  llvm/test/CodeGen/AArch64/GlobalISel/legalize-global.mir
  llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir
  llvm/test/CodeGen/AArch64/GlobalISel/localizer.mir
  llvm/test/CodeGen/AArch64/arm64-custom-call-saved-reg.ll
  llvm/test/CodeGen/AArch64/arm64-ldxr-stxr.ll
  llvm/test/CodeGen/AArch64/dllimport.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78465.258633.patch
Type: text/x-patch
Size: 26742 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200420/b74beb92/attachment.bin>


More information about the llvm-commits mailing list