[PATCH] D61787: [GlobalISel Legalizer] Improve artifact combiner

Petar Avramovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 10 08:17:45 PDT 2019


Petar.Avramovic created this revision.
Petar.Avramovic added reviewers: atanasyan, petarj, arsenm, volkan, dsanders, rovka, qcolombet, aemerson, aditya_nandakumar.
Herald added subscribers: llvm-commits, javed.absar, kristof.beyls, nhaehnle, wdng, jvesely.
Herald added a project: LLVM.

The main idea is to allow legalization of chained artifacts by waiting for resolution of unresolved uses.

Therefore, this patch introduces two types of artifacts: 
Artifact and Auxiliary Artifact.

Artifact (G_ZEXT, G_ANYEXT, G_SEXT, G_UNMERGE_VALUES, G_EXTRACT) 
is able to perform combine with 
Auxiliary Artifact (G_TRUNC, G_MERGE_VALUES, G_CONCAT_VECTORS, G_BUILD_VECTOR).

The idea is not to legalize an Auxiliary Artifact if there still exists a possibility that it can be combined with some other Artifact. 
With this new setup, we will not have to make complicated rules in LegalizerInfo that have a purpose to not crash Artifact Combiner,
i.e. the goal here is to avoid situation to ask for Auxiliary Artifact if it is legal when answer must be yes (if we don't want to crash).
We want to avoid the following sequence of events:
legalization of Auxiliary Artifact (e.g. G_MERGE_VALUES) into a legal instruction, 
that will disappear by combining with some other Artifact (e.g. G_UNMERGE_VALUES) that appears later.

Additionally, in this moment, Auxiliary Artifact G_TRUNC can jump to uses of its operand 0, and preform combine from them (this uses are Artifacts). 
This patch removes such behavior since it disturbs order in which artifacts are processed.

Legalization of chained artifact is done by waiting for resolution of unresolved use.
The way we achieve this is:
When artifact fails to combine check if it has unresolved uses:

1. Unprocessed Artifact (Artifact in ArtifactList or TryLaterArtifactList)
2. Use in InstList. This can be either: a) Artifact that was turned into instruction and is waiting to be legalized b) Instruction that was created during some combine e.g. G_AND when combining G_ZEXT and G_TRUNC
3. Use Artifact in AuxiliaryArtifactList, since combine was not possible there is a chance that appropriate artifact will appear after legalization of Auxiliary Artifact. When this happens, move Auxiliary Artifact to InstList to be Legalized

When there was an unresolved use, move Artifact to TryLaterArtifactList and try again later.


Repository:
  rL LLVM

https://reviews.llvm.org/D61787

Files:
  include/llvm/CodeGen/GlobalISel/GISelWorkList.h
  lib/CodeGen/GlobalISel/Legalizer.cpp
  test/CodeGen/AArch64/GlobalISel/legalize-unmerge-values.mir
  test/CodeGen/AArch64/GlobalISel/legalizer-combiner-zext-trunc-crash.mir
  test/CodeGen/AMDGPU/GlobalISel/artifact-combiner-sext.mir
  test/CodeGen/AMDGPU/GlobalISel/artifact-combiner-zext.mir
  test/CodeGen/AMDGPU/GlobalISel/legalize-and.mir
  test/CodeGen/AMDGPU/GlobalISel/legalize-extract.mir
  test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def.mir
  test/CodeGen/AMDGPU/GlobalISel/legalize-or.mir
  test/CodeGen/AMDGPU/GlobalISel/legalize-unmerge-values-xfail.mir
  test/CodeGen/AMDGPU/GlobalISel/legalize-unmerge-values.mir
  test/CodeGen/AMDGPU/GlobalISel/legalize-xor.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61787.199019.patch
Type: text/x-patch
Size: 39698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190510/a690bbd2/attachment-0001.bin>


More information about the llvm-commits mailing list