This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add a special case to lowerSELECT for select of 2 constants with a SETLT condition.
ClosedPublic

Authored by craig.topper on Mar 20 2021, 10:17 AM.

Details

Summary

If the constants have a difference of 1 we can convert one to
the other by adding or subtracting the condition.

We have a DAG combine for this, but it only runs before type
legalization. If the select is introduced later during type
legalization or op legalization we will miss it.

We don't need a specific condition, but some conditions are
harder to materialize than others on RISCV. I know that SETLT
will be a single instruction and it is what is used by the
motivating pattern from signed saturating add/sub.

Diff Detail

Event Timeline

craig.topper created this revision.Mar 20 2021, 10:17 AM
craig.topper requested review of this revision.Mar 20 2021, 10:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2021, 10:17 AM
Herald added a subscriber: MaskRay. · View Herald Transcript
frasercrmck added inline comments.Mar 23 2021, 4:11 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
2252

I take it that this is guaranteed valid by setBooleanContents(ZeroOrOneBooleanContent)? If the cond was 0/-1 then we'd be in trouble.

asb accepted this revision.Apr 1 2021, 4:03 AM

Needs a rebase for the test changes to apply, but this LGTM.

This revision is now accepted and ready to land.Apr 1 2021, 4:03 AM