From 3557926315cee46b72d39acc44efd65e89b9f4e7 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 14 Apr 2017 06:43:34 +0000 Subject: [PATCH] [ValueTracking] Calculate the KnownZeros for Intrinsic::ctpop without using a temporary APInt to count leading zeros on. The APInt was created from an 'unsigned' and we just wanted to know how many bits the value needed to represent it. We can just use Log2_32 from MathExtras.h to get the info. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300309 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ValueTracking.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index 8479bc76c59..d871e83f222 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -1428,11 +1428,8 @@ static void computeKnownBitsFromOperator(const Operator *I, APInt &KnownZero, // We can bound the space the count needs. Also, bits known to be zero // can't contribute to the population. unsigned BitsPossiblySet = BitWidth - KnownZero2.countPopulation(); - unsigned LeadingZeros = - APInt(BitWidth, BitsPossiblySet).countLeadingZeros(); - assert(LeadingZeros <= BitWidth); - KnownZero.setHighBits(LeadingZeros); - KnownOne &= ~KnownZero; + unsigned LowBits = Log2_32(BitsPossiblySet)+1; + KnownZero.setBitsFrom(LowBits); // TODO: we could bound KnownOne using the lower bound on the number // of bits which might be set provided by popcnt KnownOne2. break; -- 2.40.0