This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] refactor ctlz/cttz folds (NFCI)
ClosedPublic

Authored by spatel on Aug 5 2016, 1:24 PM.

Details

Summary

I suggested this change in D23134, but it was not expressed clearly enough. Maybe reading the code is easier? :)

The existing transforms for ctlz/cttz are almost identical, and the code is obviously copy/pasted.

We just need to shift the mask over for ctlz to see if our operand gives us a known constant value.

I've also added the FIXME comment that I suggested because I think this (and several other existing transforms in this file) could be moved to InstSimplify.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 67004.Aug 5 2016, 1:24 PM
spatel retitled this revision from to [InstCombine] refactor ctlz/cttz folds (NFCI).
spatel updated this object.
spatel added reviewers: deadalnix, majnemer.
spatel added a subscriber: llvm-commits.
spatel updated this revision to Diff 67010.Aug 5 2016, 1:40 PM

Use getHighBitsSet() to mimic the existing code; more symmetrical this way.

majnemer added inline comments.Aug 5 2016, 2:53 PM
lib/Transforms/InstCombine/InstCombineCalls.cpp
1107 ↗(On Diff #67010)

Can't IsTZ be divined from the II?

1110 ↗(On Diff #67010)

auto *

spatel marked 2 inline comments as done.Aug 5 2016, 3:07 PM
spatel added inline comments.
lib/Transforms/InstCombine/InstCombineCalls.cpp
1107 ↗(On Diff #67010)

Yep - that looks nicer.

1110 ↗(On Diff #67010)

Done.

spatel updated this revision to Diff 67031.Aug 5 2016, 3:08 PM
spatel marked 2 inline comments as done.

Patch updated:

  1. Check intrinsic ID inside the function to simplify caller and API.
  2. Use auto with dyn_cast.
spatel updated this revision to Diff 67032.Aug 5 2016, 3:09 PM

The previous draft was missing the 'auto' change.

majnemer accepted this revision.Aug 5 2016, 3:12 PM
majnemer edited edge metadata.

LGTM

This revision is now accepted and ready to land.Aug 5 2016, 3:12 PM
This revision was automatically updated to reflect the committed changes.