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:
- Unprocessed Artifact (Artifact in ArtifactList or TryLaterArtifactList)
- 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.
- 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.