[llvm] 04f33a3 - [APInt] Use a std::move() to avoid a copy in the loop in multiplicativeInverse. (#87655)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 8 20:38:32 PDT 2024


Author: Craig Topper
Date: 2024-04-08T20:38:29-07:00
New Revision: 04f33a3ac2e8ca96840606f812eaef974ff61c80

URL: https://github.com/llvm/llvm-project/commit/04f33a3ac2e8ca96840606f812eaef974ff61c80
DIFF: https://github.com/llvm/llvm-project/commit/04f33a3ac2e8ca96840606f812eaef974ff61c80.diff

LOG: [APInt] Use a std::move() to avoid a copy in the loop in multiplicativeInverse. (#87655)

This allows the subtract to reuse the storage of T. T will be assigned
over by the condition on the next iteration. I think assigning over a
moved from value should be ok.

Added: 
    

Modified: 
    llvm/lib/Support/APInt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 224ea0924f0aaa..8825025ec32134 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -1249,7 +1249,7 @@ APInt APInt::multiplicativeInverse() const {
   APInt Factor = *this;
   APInt T;
   while (!(T = *this * Factor).isOne())
-    Factor *= 2 - T;
+    Factor *= 2 - std::move(T);
   return Factor;
 }
 


        


More information about the llvm-commits mailing list