diff options
| author | Craig Topper <craig.topper@gmail.com> | 2017-04-01 20:30:57 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@gmail.com> | 2017-04-01 20:30:57 +0000 |
| commit | 278ebd2f98bd43cbf5db427cba4df660e591ff2b (patch) | |
| tree | 3dd2dcc7827091621cc5f0af0ef6e1e8eb52ffdf /llvm/lib/Support | |
| parent | 16fe5822f21c0b6de50c563fbbc8e2ba12495c22 (diff) | |
| download | bcm5719-llvm-278ebd2f98bd43cbf5db427cba4df660e591ff2b.tar.gz bcm5719-llvm-278ebd2f98bd43cbf5db427cba4df660e591ff2b.zip | |
[APInt] Allow GreatestCommonDivisor to take rvalue inputs efficiently. Use moves instead of copies in the loop.
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.
Reviewers: dblaikie, RKSimon, hans
Reviewed By: dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D31572
llvm-svn: 299314
Diffstat (limited to 'llvm/lib/Support')
| -rw-r--r-- | llvm/lib/Support/APInt.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index d6139504f9a..0d4255da7f0 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -876,13 +876,11 @@ APInt APInt::reverseBits() const { return Reversed; } -APInt llvm::APIntOps::GreatestCommonDivisor(const APInt& API1, - const APInt& API2) { - APInt A = API1, B = API2; +APInt llvm::APIntOps::GreatestCommonDivisor(APInt A, APInt B) { while (!!B) { - APInt T = B; - B = A.urem(B); - A = T; + APInt R = A.urem(B); + A = std::move(B); + B = std::move(R); } return A; } |

