Page MenuHomePhabricator

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

Authored by dmgreen on Tue, Nov 22, 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.Tue, Nov 22, 4:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptTue, Nov 22, 4:21 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
dmgreen requested review of this revision.Tue, Nov 22, 4:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptTue, Nov 22, 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.Wed, Nov 23, 7:52 AM

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

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