This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Propagate extends through G_PHIs into the incoming value blocks.
ClosedPublic

Authored by aemerson on Jan 29 2021, 3:06 PM.

Details

Summary

This combine tries to do inter-block hoisting of extends of G_PHIs, into the originating blocks of the phi's incoming value. The idea is to expose further optimization opportunities that are normally obscured by the PHI.

Some basic heuristics, and a target hook for AArch64 is added, to allow tuning. E.g. if the extend is used by a G_PTR_ADD, it doesn't perform this combine since it may be folded into the addressing mode during selection.

There are very minor code size improvements on AArch64 -Os, but the real benefit is that it unlocks optimizations like AArch64 conditional compares on some benchmarks.

Diff Detail

Event Timeline

aemerson created this revision.Jan 29 2021, 3:06 PM
aemerson requested review of this revision.Jan 29 2021, 3:06 PM
paquette added inline comments.Jan 29 2021, 4:02 PM
llvm/include/llvm/CodeGen/TargetInstrInfo.h
1933
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3598

This can have at most 3 elements before returning false, so I guess you might as well cut the loop short here.

3606

This can probably just go in the loop above, which should allow you to bail out early as well.

3632

Why not SmallSetVector?

paquette added inline comments.Jan 29 2021, 4:07 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3572

Change "don't do this until heuristics are better" into a TODO so it's easier for people to find?

3576
3633

Why not SmallDenseMap?

arsenm added inline comments.Jan 29 2021, 5:51 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3590

Folded into what?

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
7192–7195

return x == y;

aemerson added inline comments.Jan 29 2021, 6:10 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3590

Could be anything. The idea is that extensions which are "free" because they'd be folded into another operation, are not worth propagating.

3598

Unless I'm misunderstanding, this would prevent us from knowing how many unique incoming values there are, if we stop early. G_PHIs can have any number of operands.

3606

Sure.

3633

Yeah, will change.

paquette added inline comments.Feb 1 2021, 10:30 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3598

Oh, I see. Makes sense.

aemerson updated this revision to Diff 321162.Feb 3 2021, 10:50 AM

Address comments. Simplify some of the logic/early exit if we detect too many unique incoming values.

This revision is now accepted and ready to land.Feb 12 2021, 10:56 AM
This revision was landed with ongoing or failed builds.Feb 12 2021, 11:53 AM
This revision was automatically updated to reflect the committed changes.