[llvm] r271556 - Make APInt negate just do a 2's complement negate instead of subtract. NFC.
Pete Cooper via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 2 11:11:54 PDT 2016
Author: pete
Date: Thu Jun 2 13:11:54 2016
New Revision: 271556
URL: http://llvm.org/viewvc/llvm-project?rev=271556&view=rev
Log:
Make APInt negate just do a 2's complement negate instead of subtract. NFC.
This is part of an effort to shave allocations from APInt heavy paths. I'll
be moving many of the other operators to r-value references soon and this is
a step towards doing that without too much duplication.
Saves 15k allocations when doing 'opt -O2 verify-uselistorder.bc'.
Modified:
llvm/trunk/include/llvm/ADT/APInt.h
Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=271556&r1=271555&r2=271556&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Thu Jun 2 13:11:54 2016
@@ -625,7 +625,12 @@ public:
/// Negates *this using two's complement logic.
///
/// \returns An APInt value representing the negation of *this.
- APInt operator-() const { return APInt(BitWidth, 0) - (*this); }
+ APInt operator-() const {
+ APInt Result(*this);
+ Result.flipAllBits();
+ ++Result;
+ return Result;
+ }
/// \brief Logical negation operator.
///
More information about the llvm-commits
mailing list