This is an archive of the discontinued LLVM Phabricator instance.

Switch to Select range optimization
Needs ReviewPublic

Authored by kariddi on Nov 14 2014, 9:45 AM.

Details

Reviewers
hans
Summary

This is a follow up for http://reviews.llvm.org/D5620 .

This optimization tries one step further trying to detect cases where we can use a pivot to distinguish between the two case groups.

At the moment if the optimization detects that a default target is present in the switch it bails out, but it tries to see if that default can trigger or not.

Diff Detail

Event Timeline

kariddi updated this revision to Diff 16222.Nov 14 2014, 9:45 AM
kariddi retitled this revision from to Switch to Select range optimization.
kariddi updated this object.
kariddi edited the test plan for this revision. (Show Details)
kariddi added a reviewer: hans.
kariddi set the repository for this revision to rL LLVM.
kariddi added a subscriber: Unknown Object (MLST).
hans edited edge metadata.Nov 14 2014, 12:09 PM

The patch seems to have been uploaded without context. If you're uploading the patch manually (i.e. not using arcanist), please generate the diff with -U99999. That way it's much easier to look at it in the review tool.

lib/Transforms/Utils/SimplifyCFG.cpp
3540

I don't see any need for auto here..

for (ConstantInt *Case : Cases)

would be clearer, and it avoids making Case a reference to a pointer type, which seems unnecessary.

3721

Using known bits to figure out if the default case can trigger is clever. Other optimizations would benefit from this too, so I think SimplifyCFG should have a separate transformation that does this analysis and makes the default case unreachable. That way more optimizations benefit, and the code here becomes simpler.

Ok, thanks Hans!
I will do it next time. I usually use "git diff" for generating the diff , I'll take a look at Arcanist too though.

lib/Transforms/Utils/SimplifyCFG.cpp
3540

Will do.

3721

Do you think I should hoist it to a separate static function in SimplifyCFG?

Is this what you had in mind?