This is an archive of the discontinued LLVM Phabricator instance.

Select elimination pass
AbandonedPublic

Authored by Gerolf on Sep 2 2014, 12:45 PM.

Details

Reviewers
echristo
Summary

In special cases select instructions can be eliminated by
replacing them with a cheaper bitwise operation. The instance implemented
by this pass is %x=icmp.eq; %y=select %x,%r, null; %z=icmp.eq %y, null;
br %z,true, false ==> %x=icmp.ne; %y=icmp.eq %r,null; %z=or %x,%y; br
%z,true,false. The optimization is global and performed only when all uses
of the select result can be replaced by the select true value. For this
dominator information is used.

Diff Detail

Event Timeline

Gerolf updated this revision to Diff 13178.Sep 2 2014, 12:45 PM
Gerolf retitled this revision from to Select elimination pass.
Gerolf updated this object.
Gerolf edited the test plan for this revision. (Show Details)
Gerolf added a reviewer: echristo.
Gerolf added a subscriber: Unknown Object (MLST).

Why isn't this an instcombine on select instructions?

majnemer added inline comments.
lib/Transforms/Scalar/SelectElimination.cpp
129–132

auto would be more concise here, the type is also in the dyn_cast template argument.

146–147

You can fold this dyn_cast into the if.

174

Should be capitalized.

185–186

You can fold these together too.

Gerolf updated this revision to Diff 13238.Sep 3 2014, 8:41 PM

Select Elimination Pass update

Improved readability and addressed review:

  • moved code that replaces select into a function replaceSelectWithOr()
  • moved the checks for the selection condition compare into functio isChainSelectCmpEQBranch().
  • cleared up some clutter as David M. had suggested

Hi Gerolf,

I added a few comments and questions inline.

-Juergen

lib/Transforms/Scalar/SelectElimination.cpp
80

Your pass doesn't preserve the CFG?

82

We don't add the function name in the comments anymore.

105

ditto

118

ditto

145

ditto

170

ditto

175

I would add an assert with isa<ICmpInst> and then use just cast<ICmpInst>, since you are not checking the result of the dyn_cast anyways.

212

Why is the iterator incremented in the loop?

214

You could combine this with dyn_cast to one line or you could invert the condition and add a continue to reduce the indentation of the code afterwards.

mcrosier added inline comments.
lib/Transforms/Scalar/SelectElimination.cpp
61

The command-line option should be in the PassManagerBuilder. Rather than return from the runOnFunction, we should not add the pass to the pass manager.

Gerolf abandoned this revision.Sep 8 2014, 8:58 PM

I integrate the optimization into InstCombine and close this review. @Juergen, Chad, Dave and Chandler - thank you for your review time and comments.