This is an archive of the discontinued LLVM Phabricator instance.

[SelectOpt] Don't treat LogicalAnd/LogicalOr as selects
ClosedPublic

Authored by dmgreen on Nov 22 2022, 4:21 AM.

Details

Summary

A select i1 %c, i1 true, i1 %d is just an or and a select i1 %c, i1 %d, i1 false is just an and. There are better treated as such in the logic of SelectOpt, allowing the backend to optimize them to and/or directly.

Diff Detail

Event Timeline

dmgreen created this revision.Nov 22 2022, 4:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 22 2022, 4:21 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
dmgreen requested review of this revision.Nov 22 2022, 4:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 22 2022, 4:21 AM

This looks good. Sotiris may help with a quick benchmarking for the patch.

This looks fine to me as well and it is okay performance-wise (within noise margins for some testing I did).
My only suggestion is to separate this check in a separate function. See inline comment.

llvm/lib/CodeGen/SelectOptimize.cpp
538

I would suggest moving the added check to a new static function maybe called isSpecialSelect and continue if it returns true. It will make the code cleaner and maybe we will add more special select cases that should not be changed to branches.

dmgreen updated this revision to Diff 477508.Nov 23 2022, 7:52 AM

Thanks - that sounds good. I've created a function like you suggest.

apostolakis accepted this revision.Nov 23 2022, 11:42 AM
This revision is now accepted and ready to land.Nov 23 2022, 11:42 AM
This revision was landed with ongoing or failed builds.Nov 24 2022, 6:30 AM
This revision was automatically updated to reflect the committed changes.