This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Handle sequences of trunc(sext/zext/anyext...) in artifact combiner
ClosedPublic

Authored by dzhidzhoev on Aug 1 2023, 3:41 PM.

Details

Summary

trunc(sext/zext/anyext... x) -> x pattern is handled in artifact combiner to avoid extra copy instructions in https://reviews.llvm.org/D156831.

Diff Detail

Event Timeline

dzhidzhoev created this revision.Aug 1 2023, 3:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2023, 3:41 PM
dzhidzhoev requested review of this revision.Aug 1 2023, 3:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2023, 3:41 PM
jroelofs added inline comments.
llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
330

ISTM this should do m_GAnyExt so we also get coverage for trunc(zext x) -> x.

334
arsenm added inline comments.Aug 1 2023, 4:47 PM
llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
240

Can we start moving all of this into ArtifactValueFinder instead of incrementally finding every permutation of casts?

dzhidzhoev updated this revision to Diff 546914.Aug 3 2023, 9:58 AM

Addressed @jroelofs and @arsenm comments.
Now we find sequences of trunc/sext/anyext/zext instructions, starting with trunc(...),
and replace the destination of trunc with the source of nested instructions if
the destination and "nested" source types are matching.

dzhidzhoev retitled this revision from [GlobalISel] Handle trunc(sext x) in artifact combiner to [GlobalISel] Handle sequences of trunc(sext/zext/anyext...) in artifact combiner.Aug 3 2023, 9:59 AM
dzhidzhoev edited the summary of this revision. (Show Details)
dzhidzhoev edited the summary of this revision. (Show Details)
jroelofs accepted this revision.Aug 3 2023, 4:23 PM

LGTM

This revision is now accepted and ready to land.Aug 3 2023, 4:23 PM

Some more comments, otherwise LGTM with some nice codegen improvements.

llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
330

Can just use Register here since it auto doesn't buy much.

758–764

Can invert this condition to early-exit if StartBit + Size > SrcSize

dzhidzhoev updated this revision to Diff 547156.Aug 4 2023, 3:55 AM

Addressed @aemerson comments.