From a48f3f3de2aee009c3f6975b239d42b8dca88bdb Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 18 Mar 2017 04:01:29 +0000 Subject: [PATCH] [ValueTracking] Add APInt::setSignBit and use it to replace ORing with getSignBit which will malloc if the bit width is larger than 64. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298180 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/APInt.h | 5 +++++ lib/Analysis/ValueTracking.cpp | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 8e6c7bc42e7..8d8c898a053 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -1175,6 +1175,11 @@ public: /// Set the given bit to 1 whose position is given as "bitPosition". void setBit(unsigned bitPosition); + /// Set the sign bit to 1. + void setSignBit() { + setBit(BitWidth - 1); + } + /// Set the bits from loBit (inclusive) to hiBit (exclusive) to 1. void setBits(unsigned loBit, unsigned hiBit) { assert(hiBit <= BitWidth && "hiBit out of range"); diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index a3d4198edcb..38d9c290bfc 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -321,11 +321,11 @@ static void computeKnownBitsAddSub(bool Add, const Value *Op0, const Value *Op1, // Adding two non-negative numbers, or subtracting a negative number from // a non-negative one, can't wrap into negative. if (LHSKnownZero.isNegative() && KnownZero2.isNegative()) - KnownZero |= APInt::getSignBit(BitWidth); + KnownZero.setSignBit(); // Adding two negative numbers, or subtracting a non-negative number from // a negative one, can't wrap into non-negative. else if (LHSKnownOne.isNegative() && KnownOne2.isNegative()) - KnownOne |= APInt::getSignBit(BitWidth); + KnownOne.setSignBit(); } } } @@ -732,7 +732,7 @@ static void computeKnownBitsFromAssume(const Value *V, APInt &KnownZero, if (RHSKnownZero.isNegative()) { // We know that the sign bit is zero. - KnownZero |= APInt::getSignBit(BitWidth); + KnownZero.setSignBit(); } // assume(v >_s c) where c is at least -1. } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && @@ -743,7 +743,7 @@ static void computeKnownBitsFromAssume(const Value *V, APInt &KnownZero, if (RHSKnownOne.isAllOnesValue() || RHSKnownZero.isNegative()) { // We know that the sign bit is zero. - KnownZero |= APInt::getSignBit(BitWidth); + KnownZero.setSignBit(); } // assume(v <=_s c) where c is negative } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && @@ -754,7 +754,7 @@ static void computeKnownBitsFromAssume(const Value *V, APInt &KnownZero, if (RHSKnownOne.isNegative()) { // We know that the sign bit is one. - KnownOne |= APInt::getSignBit(BitWidth); + KnownOne.setSignBit(); } // assume(v <_s c) where c is non-positive } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && @@ -765,7 +765,7 @@ static void computeKnownBitsFromAssume(const Value *V, APInt &KnownZero, if (RHSKnownZero.isAllOnesValue() || RHSKnownOne.isNegative()) { // We know that the sign bit is one. - KnownOne |= APInt::getSignBit(BitWidth); + KnownOne.setSignBit(); } // assume(v <=_u c) } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && -- 2.50.1