This is an archive of the discontinued LLVM Phabricator instance.

Teach SimplifyCFG to Create Switches from InstCombine Or Mask'd Comparisons
ClosedPublic

Authored by tjablin on Jun 15 2016, 12:41 PM.

Details

Summary

I am following Chandler's suggestion by teaching SimplifyCFG to recognize the Or-Mask trick that InstCombine uses to reduce the number of comparisons. Specifically, InstCombine can turn:

(i == 5334 || i == 5335)

into:

((i | 1) == 5335)

SimplifyCFG was already able to detect the pattern:

(i == 5334 || i == 5335)

to:

((i & -2) == 5334)

This patch supersedes D21315 and resolves PR27555 (https://llvm.org/bugs/show_bug.cgi?id=27555).

Diff Detail

Event Timeline

tjablin updated this revision to Diff 60882.Jun 15 2016, 12:41 PM
tjablin retitled this revision from to Teach SimplifyCFG to Create Switches from InstCombine Or Mask'd Comparisons.
tjablin updated this object.
tjablin added a subscriber: llvm-commits.
chandlerc edited edge metadata.Jun 15 2016, 3:11 PM

Wow, thanks for digging into this.

Can you separate out the bug fix for the current pattern matching and send that first? Then we can have a second patch that just extends to handle the new pattern(s).

majnemer added inline comments.Jun 15 2016, 3:20 PM
lib/Transforms/Utils/SimplifyCFG.cpp
478

Why not use m_APInt?

482

Please clang-format this.

500

Ditto.

tjablin updated this revision to Diff 61059.Jun 16 2016, 7:00 PM
tjablin updated this object.
tjablin edited edge metadata.

I have split out and applied the bug fix and m_ConstantInt => m_APInt portions of the past separately. What remains is just the new functionality.

majnemer accepted this revision.Jun 23 2016, 9:17 AM
majnemer edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jun 23 2016, 9:17 AM
cycheng closed this revision.Jun 23 2016, 7:07 PM
cycheng edited edge metadata.

Committed r273639 (On behalf of Tom)