[llvm] fc5da39 - [llvm] Use llvm::Log2_64 (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 28 11:20:54 PST 2023


Author: Kazu Hirata
Date: 2023-01-28T11:20:47-08:00
New Revision: fc5da3969f2fd6065ab6b93f9586ece9002366ce

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

LOG: [llvm] Use llvm::Log2_64 (NFC)

Added: 
    

Modified: 
    llvm/include/llvm/MCA/Support.h
    llvm/include/llvm/Support/ScaledNumber.h
    llvm/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MCA/Support.h b/llvm/include/llvm/MCA/Support.h
index 1debf376a0796..e5e6278171051 100644
--- a/llvm/include/llvm/MCA/Support.h
+++ b/llvm/include/llvm/MCA/Support.h
@@ -99,7 +99,7 @@ void computeProcResourceMasks(const MCSchedModel &SM,
 // the highest bit set can be used to construct a resource mask identifier.
 inline unsigned getResourceStateIndex(uint64_t Mask) {
   assert(Mask && "Processor Resource Mask cannot be zero!");
-  return (std::numeric_limits<uint64_t>::digits - countLeadingZeros(Mask)) - 1;
+  return llvm::Log2_64(Mask);
 }
 
 /// Compute the reciprocal block throughput from a set of processor resource

diff  --git a/llvm/include/llvm/Support/ScaledNumber.h b/llvm/include/llvm/Support/ScaledNumber.h
index a5261e419986f..ea01ff691aa0d 100644
--- a/llvm/include/llvm/Support/ScaledNumber.h
+++ b/llvm/include/llvm/Support/ScaledNumber.h
@@ -192,7 +192,8 @@ inline std::pair<int32_t, int> getLgImpl(DigitsT Digits, int16_t Scale) {
     return std::make_pair(INT32_MIN, 0);
 
   // Get the floor of the lg of Digits.
-  int32_t LocalFloor = sizeof(Digits) * 8 - countLeadingZeros(Digits) - 1;
+  static_assert(sizeof(Digits) <= sizeof(uint64_t));
+  int32_t LocalFloor = llvm::Log2_64(Digits);
 
   // Get the actual floor.
   int32_t Floor = Scale + LocalFloor;

diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp
index 01a4498991d8c..a4fe81b137e02 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp
@@ -1701,7 +1701,7 @@ getBitfieldInvertedMaskOpValue(const MCInst &MI, unsigned Op,
   const MCOperand &MO = MI.getOperand(Op);
   uint32_t v = ~MO.getImm();
   uint32_t lsb = llvm::countr_zero(v);
-  uint32_t msb = (32 - llvm::countl_zero(v)) - 1;
+  uint32_t msb = llvm::Log2_32(v);
   assert(v != 0 && lsb < 32 && msb < 32 && "Illegal bitfield mask!");
   return lsb | (msb << 5);
 }


        


More information about the llvm-commits mailing list