This is an archive of the discontinued LLVM Phabricator instance.

[APInt] Allow GreatestCommonDivisor to take rvalue inputs efficiently. Use moves instead of copies in the loop.
ClosedPublic

Authored by craig.topper on Apr 1 2017, 11:53 AM.

Details

Summary

GreatestComonDivisor currently makes a copy of both its inputs. Then in the loop we do one move and two copies, plus any allocation the urem call does.

This patch changes it to take its inputs by value so that we can do a move of any rvalue inputs instead of copying. Then in the loop we do 3 move assignments and no copies. This way the only possible allocations we have in the loop is from the urem call.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 1 2017, 11:53 AM
dblaikie accepted this revision.Apr 1 2017, 12:02 PM

Looks fine (:

This revision is now accepted and ready to land.Apr 1 2017, 12:02 PM
This revision was automatically updated to reflect the committed changes.