This is an archive of the discontinued LLVM Phabricator instance.

[APInt] Move operator~ out of line to make it better able to reused memory allocation from temporary objects
ClosedPublic

Authored by craig.topper on Mar 5 2017, 12:03 AM.

Details

Summary

This makes operator~ take the APInt by value so if it came from a temporary APInt the move constructor will get invoked and it will be able to reuse the memory allocation from the temporary.

This is similar to what was already done for 2s complement negation.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Mar 5 2017, 12:03 AM
RKSimon edited edge metadata.Mar 5 2017, 8:22 AM

Are there any uses of this? APIntTest.cpp doesn't seem to have any.

It is used in other places for example

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2017: if (DAG.MaskedValueIsZero(N1, ~APInt::getSignBit(BitWidth))) {
8127: SignMask = ~APInt::getSignBit(SourceVT.getSizeInBits());
10226: SignMask = ~APInt::getSignBit(N0.getScalarValueSizeInBits());
10230: SignMask = ~APInt::getSignBit(IntVT.getSizeInBits());
11609: APInt Mask = ~APInt::getBitsSet(IVal.getValueSizeInBits(),

I'll see if I can construct a test case for the move behavior.

davide accepted this revision.Mar 5 2017, 3:37 PM

This looks fine. It would be nice if you could keep the doxygen comment.

This revision is now accepted and ready to land.Mar 5 2017, 3:37 PM
This revision was automatically updated to reflect the committed changes.