This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Simplify ctlz/cttz with bitreverse
ClosedPublic

Authored by xbolva00 on Apr 1 2019, 1:40 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

xbolva00 created this revision.Apr 1 2019, 1:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2019, 1:40 PM
spatel added a comment.Apr 2 2019, 5:58 AM

We don't need a full permutation of the possibilities, but can you add at least a few test variations and improvements:

  1. The 2nd param is 'false'.
  2. The type is a vector.
  3. Run '-instnamer' or manually add variable names, so we don't have nameless values.
  4. Pre-commit the baseline versions of the tests.
  5. Add a comment/link for PR41273 (should also mention that in the description/commit message).
xbolva00 updated this revision to Diff 193335.Apr 2 2019, 11:39 AM
xbolva00 edited the summary of this revision. (Show Details)
  • Added and precommited more tests
spatel accepted this revision.Apr 2 2019, 12:43 PM

LGTM - thanks!

lib/Transforms/InstCombine/InstCombineCalls.cpp
1333–1336 ↗(On Diff #193335)

Might be less hassle to not to use the builder directly:

Intrinsic::ID ID = IsTZ ? Intrinsic::ctlz : Intrinsic::cttz;
Function *F = Intrinsic::getDeclaration(II.getModule(), ID, II.getType());
return CallInst::Create(F, { X, II.getArgOperand(1) });
This revision is now accepted and ready to land.Apr 2 2019, 12:43 PM
xbolva00 updated this revision to Diff 193351.Apr 2 2019, 12:55 PM

Do not use builder.

This revision was automatically updated to reflect the committed changes.