[all-commits] [llvm/llvm-project] 61b470: [AArch64][GlobalISel] Fold constants into G_GLOBAL...

Jessica Paquette via All-commits all-commits at lists.llvm.org
Fri Feb 12 15:00:02 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 61b4702a408834228c1c139b0e9af98616774db4
      https://github.com/llvm/llvm-project/commit/61b4702a408834228c1c139b0e9af98616774db4
  Author: Jessica Paquette <jpaquette at apple.com>
  Date:   2021-02-12 (Fri, 12 Feb 2021)

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

  Log Message:
  -----------
  [AArch64][GlobalISel] Fold constants into G_GLOBAL_VALUE

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.

Differential Revision: https://reviews.llvm.org/D96624




More information about the All-commits mailing list