This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Transform sext (cmp pred, x, y) -> select (cmp pred, x, y) tval, 0
Needs RevisionPublic

Authored by paquette on Dec 16 2020, 11:01 AM.

Details

Reviewers
aemerson
arsenm
Summary

On some targets, such as AArch64, it's possible to optimize G_ICMP + G_SELECT pairs more effectively than G_ICMP + G_SEXT pairs.

Example: https://godbolt.org/z/5nd3Gf

This is a combine that already exists in the DAGCombiner (see DAGCombiner::visitSIGN_EXTEND).

Like the DAGCombiner, this uses a target hook (convertSelectOfConstantsToMath) to allow targets to choose whether they want this, or combines that change selects into extends.

For AArch64, this is a minor code size win on CTMark at -Os.

Diff Detail

Event Timeline

paquette created this revision.Dec 16 2020, 11:01 AM
paquette requested review of this revision.Dec 16 2020, 11:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2020, 11:01 AM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm added inline comments.Dec 16 2020, 7:14 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3151

Vectors should be easy to handle?

3152

This doesn't check the inputs are constants? The name seems wrong

3163–3173

This comment is pretty wordy for what it's explaining. I would expect this to defer to somewhere else to explain the concept of the bool true value

3173

s/a/an/

paquette added inline comments.Dec 17 2020, 9:41 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3152

The goal here is to avoid creating a select of constants from an extend if it will be transformed back into an extend later. So, there's no reason to check for constants here.

arsenm requested changes to this revision.Mar 30 2021, 5:56 PM
arsenm added inline comments.
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3152

The DAG here skips this if the compare result type isn't i1, which is probably still a good idea

This revision now requires changes to proceed.Mar 30 2021, 5:56 PM

Reverse ping

Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2022, 2:05 PM