From dbd6219f8197c2b95b33e7a83d02d87721eff649 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 11 May 2017 18:40:53 +0000 Subject: [PATCH] [APInt] Remove an APInt copy from the return of APInt::multiplicativeInverse. llvm-svn: 302816 --- llvm/lib/Support/APInt.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 0fade287d43e..bcec648ad0ca 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -1141,7 +1141,10 @@ APInt APInt::multiplicativeInverse(const APInt& modulo) const { // interested in a positive inverse. Calculate a positive one from a negative // one if necessary. A simple addition of the modulo suffices because // abs(t[i]) is known to be less than *this/2 (see the link above). - return t[i].isNegative() ? t[i] + modulo : t[i]; + if (t[i].isNegative()) + t[i] += modulo; + + return std::move(t[i]); } /// Calculate the magic numbers required to implement a signed integer division