This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Simplify zext/trunc idiom that appears when handling bitmasks.
ClosedPublic

Authored by jlebar on Jun 13 2018, 8:32 PM.

Details

Summary

Specifically, we transform

zext(2^K * (trunc X to iN)) to iM ->
2^K * (zext(trunc X to i{N-K}) to iM)<nuw>

This is helpful because pulling the 2^K out of the zext allows further
optimizations.

Event Timeline

jlebar created this revision.Jun 13 2018, 8:32 PM
sanjoy accepted this revision.Jun 14 2018, 10:01 AM

lgtm

llvm/lib/Analysis/ScalarEvolution.cpp
1771

SA is a bad name for a SCEVMulExpr -- should be SM or Mul. Do you mind fixing this in a followup CL while you're here?

1800

Let's s/TruncTy/NewTruncTy for consistency with NewTruncBits

1801

Super minor issue - if NewTruncBits < 1 then IntegerType::get would have asserted already. If you want to keep this assert for the better error message it is probably better to put it before IntegerType::get.

This revision is now accepted and ready to land.Jun 14 2018, 10:01 AM
jlebar marked 3 inline comments as done.Jun 14 2018, 10:17 AM

Thank you for the reviews, Sanjoy!

Will push with your suggested changes.

llvm/lib/Analysis/ScalarEvolution.cpp
1771

Will do.

1801

Sure, let's just remove this assert.

This revision was automatically updated to reflect the committed changes.
jlebar marked 2 inline comments as done.