This is an archive of the discontinued LLVM Phabricator instance.

[APInt] Use lshrInPlace to replace lshr where possible
ClosedPublic

Authored by craig.topper on Apr 18 2017, 12:11 AM.

Details

Summary

This patch uses lshrInPlace to replace code where the object that lshr is called on is being overwritten with the result.

This adds an lshrInPlace(const APInt &) version as well.

This also makes lshrInPlace return a reference to *this so it can be used in some other special cases.

For example:

Elt = Elt.lshr(Index).zextOrTrunc(Length);

to

Elt = Elt.lshrInPlace(Index).zextOrTrunc(Length);

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Apr 18 2017, 12:11 AM
RKSimon added inline comments.Apr 18 2017, 4:00 AM
include/llvm/ADT/APInt.h
892 ↗(On Diff #95531)

Other than operators we don't tend to use this pattern to return *this - is it a good idea to introduce it?

hans edited edge metadata.Apr 18 2017, 9:43 AM

Besides the return *this issue, this looks great!

include/llvm/ADT/APInt.h
892 ↗(On Diff #95531)

I'm also not sure about this one. While I can see that it would be convenient, it doesn't seem like it would apply in that many places, and it could potentially be a source of subtle bugs, i.e. the reader might not notice the the variable gets modified in-place when this is used as part of a larger expression.

I'll remove the return reference.

Dont' return *this by reference from lshrInPlace

hans accepted this revision.Apr 18 2017, 10:15 AM

lgtm

This revision is now accepted and ready to land.Apr 18 2017, 10:15 AM
This revision was automatically updated to reflect the committed changes.