This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add isel patterns for ineg+setge/le/uge/ule.
ClosedPublic

Authored by craig.topper on Jul 17 2022, 12:12 AM.

Details

Summary

setge/le/uge/ule selected by themselves require an xori with 1.
If we're negating the setcc, we can fold the xori with the neg
to create an addi with -1.

This works because xori X, 1 is equivalent to 1 - X if X is either
0 or 1. So we're doing -(1 - X) which is X-1 or X+-1.

This improves the code for selecting between 0 and -1 based on a
condition for some conditions.

Diff Detail

Event Timeline

craig.topper created this revision.Jul 17 2022, 12:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2022, 12:12 AM
craig.topper requested review of this revision.Jul 17 2022, 12:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2022, 12:12 AM
asb added a comment.Jul 17 2022, 8:03 AM

This LGTM if an explanatory comment is added.

llvm/lib/Target/RISCV/RISCVInstrInfo.td
1280–1287

It would be good to add a comment here that expresses some of the same information used in the patch description, explaining why this pattern is valid.

llvm/test/CodeGen/RISCV/select-const.ll
870

Nit: Unwanted additional blank line

Address review comments

asb accepted this revision.Jul 18 2022, 2:47 AM

LGTM.

This revision is now accepted and ready to land.Jul 18 2022, 2:47 AM
This revision was landed with ongoing or failed builds.Jul 18 2022, 9:55 AM
This revision was automatically updated to reflect the committed changes.