This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Optimize x <s -1 ? x : -1. Improve x >u 1 ? x : 1.
ClosedPublic

Authored by craig.topper on Aug 19 2022, 10:40 AM.

Details

Summary

Similar to D132211, we can optimize x <s -1 ? x : -1 -> x <s 0 ? x : -1

Also improve the unsigned case from D132211 to use x != 0 which
will give a bnez instruction which might be compressible.

Diff Detail

Event Timeline

craig.topper created this revision.Aug 19 2022, 10:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2022, 10:40 AM
craig.topper requested review of this revision.Aug 19 2022, 10:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2022, 10:40 AM
craig.topper added inline comments.Aug 19 2022, 10:44 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
4089

I dropped the non-constant RHS check here because it doesn't matter for the correctness of the combine and an all constant setcc should have been DAG combined away.

4090

Remove the second call to isOneConstant by checking if LHS == FalseV since we already know LHS is 1. These two changes improve the similarity with the new combine introduced here.

liaolucy accepted this revision.Aug 21 2022, 6:46 AM

LGTM, thanks.
Note, rebase first.

This revision is now accepted and ready to land.Aug 21 2022, 6:46 AM