[llvm] r301736 - [ConstantRange] Improve the efficiency of one of the ConstantRange constructors.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 28 22:08:52 PDT 2017


Author: ctopper
Date: Sat Apr 29 00:08:52 2017
New Revision: 301736

URL: http://llvm.org/viewvc/llvm-project?rev=301736&view=rev
Log:
[ConstantRange] Improve the efficiency of one of the ConstantRange constructors.

We were default constructing the Lower/Upper APInts. Then creating min or max value, then doing a move assignment to Lower and copy assignment to upper. The copy assignment operator in particular has an out of line function call that has to examine whether or not a previous allocation exists that can be reused which of course it can't in this case.

The new code creates the min/max value first, move constructs Lower from it then copy constructs Upper from Lower.

This also seems to have convinced a self host build that this constructor can be inlined more readily into other methods in ConstantRange.

Modified:
    llvm/trunk/lib/IR/ConstantRange.cpp

Modified: llvm/trunk/lib/IR/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantRange.cpp?rev=301736&r1=301735&r2=301736&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantRange.cpp (original)
+++ llvm/trunk/lib/IR/ConstantRange.cpp Sat Apr 29 00:08:52 2017
@@ -29,12 +29,9 @@
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
-ConstantRange::ConstantRange(uint32_t BitWidth, bool Full) {
-  if (Full)
-    Lower = Upper = APInt::getMaxValue(BitWidth);
-  else
-    Lower = Upper = APInt::getMinValue(BitWidth);
-}
+ConstantRange::ConstantRange(uint32_t BitWidth, bool Full)
+    : Lower(Full ? APInt::getMaxValue(BitWidth) : APInt::getMinValue(BitWidth)),
+      Upper(Lower) {}
 
 ConstantRange::ConstantRange(APInt V)
     : Lower(std::move(V)), Upper(Lower + 1) {}




More information about the llvm-commits mailing list