[PATCH] D45543: [globalisel] Add a combiner helpers for extending loads and use them in a pre-legalize combiner for AArch64

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 10:42:18 PDT 2018


dsanders updated this revision to Diff 148945.
dsanders added a comment.

Rewrite the patch such that the extends hoist up to the loads. The previous
patch had a couple problems that became clear on the bots:

- The loads could be duplicated. This is a correctness problem for volatile loads but more generally is likely to harm performance.
- The loads would sink to the extends without any hazard checking

Matching the load and folding in the uses is significantly more complex than
the previous code, but by anchoring the load where it is we both avoid both
correctness and performance issues.

The majority of the complexity comes from the need to resolve multiple
(potentially conflicting) uses. The approach this patch takes is fairly simple
in principle:

1. Pick a preferred extend (see below)
2. Fold that extend into the load
3. Fix up the other uses with truncates/extends

2 and 3 are fairly straightforward but 1 relies on heuristics to make a good
choice. The current heuristics are:

- Prefer a sext/zext over an anyext. This is on the basis that anyext is essentially free (and we therefore don't save instructions by folding it), is compatible with sext/zext, and extending with defined bits opens further optimization opportunities once we have known-bits infrastructure.
- Prefer a sext over a zext. This is on the basis that a zext typically lowers to a single immediate 'and' instruction whereas a signext typically lowers to a shift-left/shift-right sequence (except in special cases). It's therefore cheaper to zext.
- Prefer larger types. This is on the basis that G_TRUNC is usually free (Mips is a notable exception and will probably want to tweak this when its port gets this far). There is a catch with this though since it can also increase the pressure on larger registers which some targets have a smaller supply of.


Repository:
  rL LLVM

https://reviews.llvm.org/D45543

Files:
  include/llvm/CodeGen/GlobalISel/CombinerHelper.h
  lib/CodeGen/GlobalISel/Combiner.cpp
  lib/CodeGen/GlobalISel/CombinerHelper.cpp
  lib/Target/AArch64/AArch64.h
  lib/Target/AArch64/AArch64PreLegalizerCombiner.cpp
  lib/Target/AArch64/AArch64TargetMachine.cpp
  lib/Target/AArch64/CMakeLists.txt
  test/CodeGen/AArch64/GlobalISel/arm64-fallback.ll
  test/CodeGen/AArch64/GlobalISel/gisel-commandline-option.ll
  test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-extending-loads.mir
  test/CodeGen/AArch64/O0-pipeline.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45543.148945.patch
Type: text/x-patch
Size: 34746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180529/99c807a8/attachment-0001.bin>


More information about the llvm-commits mailing list