[PATCH] D96624: [AArch64][GlobalISel] Fold constants into G_GLOBAL_VALUE

Jessica Paquette via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 12 11:59:12 PST 2021


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

This is pretty much just ports `performGlobalAddressCombine` from AArch64ISelLowering. (AArch64 doesn't use the generic DAG combine for this.)

This adds a pre-legalize combine which looks for this pattern:

  %g = G_GLOBAL_VALUE @x
  %ptr1 = G_PTR_ADD %g, cst1
  %ptr2 = G_PTR_ADD %g, cst2
  ...
  %ptrN = G_PTR_ADD %g, cstN

And then, if possible, transforms it like so:

  %g = G_GLOBAL_VALUE @x
  %offset_g = G_PTR_ADD %g, -min(cst)
  %ptr1 = G_PTR_ADD %offset_g, cst1
  %ptr2 = G_PTR_ADD %offset_g, cst2
  ...
  %ptrN = G_PTR_ADD %offset_g, cstN

Where min(cst) is the smallest out of the G_PTR_ADD constants.

This means we should save at least one G_PTR_ADD.

This also updates code in the legalizer + selector which assumes that G_GLOBAL_VALUE will never have an offset and adds/updates relevant tests.


https://reviews.llvm.org/D96624

Files:
  llvm/lib/Target/AArch64/AArch64Combine.td
  llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
  llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
  llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/fold-global-offsets-target-features.mir
  llvm/test/CodeGen/AArch64/GlobalISel/fold-global-offsets.mir
  llvm/test/CodeGen/AArch64/GlobalISel/legalize-global-pic.mir
  llvm/test/CodeGen/AArch64/GlobalISel/legalize-global.mir
  llvm/test/CodeGen/AArch64/GlobalISel/select-add-low.mir
  llvm/test/CodeGen/AArch64/GlobalISel/select-gv-with-offset.mir
  llvm/test/CodeGen/AArch64/GlobalISel/select-store.mir
  llvm/test/CodeGen/AArch64/fold-global-offsets.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96624.323427.patch
Type: text/x-patch
Size: 46427 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210212/eb93a48e/attachment.bin>


More information about the llvm-commits mailing list