mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-12 22:28:22 +00:00
Rename isPowerOfTwo to isKnownToBeAPowerOfTwo.
In a previous thread it was pointed out that isPowerOfTwo is not a very precise name since it can return false for powers of two if it is unable to show that they are powers of two. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170093 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ed185daba7
commit
dbaa2376f7
@ -45,12 +45,12 @@ namespace llvm {
|
|||||||
void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne,
|
void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne,
|
||||||
const DataLayout *TD = 0, unsigned Depth = 0);
|
const DataLayout *TD = 0, unsigned Depth = 0);
|
||||||
|
|
||||||
/// isPowerOfTwo - Return true if the given value is known to have exactly one
|
/// isKnownToBeAPowerOfTwo - Return true if the given value is known to have
|
||||||
/// bit set when defined. For vectors return true if every element is known to
|
/// exactly one bit set when defined. For vectors return true if every
|
||||||
/// be a power of two when defined. Supports values with integer or pointer
|
/// element is known to be a power of two when defined. Supports values with
|
||||||
/// type and vectors of integers. If 'OrZero' is set then returns true if the
|
/// integer or pointer type and vectors of integers. If 'OrZero' is set then
|
||||||
/// given value is either a power of two or zero.
|
/// returns true if the given value is either a power of two or zero.
|
||||||
bool isPowerOfTwo(Value *V, bool OrZero = false, unsigned Depth = 0);
|
bool isKnownToBeAPowerOfTwo(Value *V, bool OrZero = false, unsigned Depth = 0);
|
||||||
|
|
||||||
/// isKnownNonZero - Return true if the given value is known to be non-zero
|
/// isKnownNonZero - Return true if the given value is known to be non-zero
|
||||||
/// when defined. For vectors return true if every element is known to be
|
/// when defined. For vectors return true if every element is known to be
|
||||||
|
@ -1457,9 +1457,9 @@ static Value *SimplifyAndInst(Value *Op0, Value *Op1, const Query &Q,
|
|||||||
// A & (-A) = A if A is a power of two or zero.
|
// A & (-A) = A if A is a power of two or zero.
|
||||||
if (match(Op0, m_Neg(m_Specific(Op1))) ||
|
if (match(Op0, m_Neg(m_Specific(Op1))) ||
|
||||||
match(Op1, m_Neg(m_Specific(Op0)))) {
|
match(Op1, m_Neg(m_Specific(Op0)))) {
|
||||||
if (isPowerOfTwo(Op0, /*OrZero*/true))
|
if (isKnownToBeAPowerOfTwo(Op0, /*OrZero*/true))
|
||||||
return Op0;
|
return Op0;
|
||||||
if (isPowerOfTwo(Op1, /*OrZero*/true))
|
if (isKnownToBeAPowerOfTwo(Op1, /*OrZero*/true))
|
||||||
return Op1;
|
return Op1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,11 +799,11 @@ void llvm::ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne,
|
|||||||
KnownZero = ZeroBits[BitWidth - 1];
|
KnownZero = ZeroBits[BitWidth - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isPowerOfTwo - Return true if the given value is known to have exactly one
|
/// isKnownToBeAPowerOfTwo - Return true if the given value is known to have exactly one
|
||||||
/// bit set when defined. For vectors return true if every element is known to
|
/// bit set when defined. For vectors return true if every element is known to
|
||||||
/// be a power of two when defined. Supports values with integer or pointer
|
/// be a power of two when defined. Supports values with integer or pointer
|
||||||
/// types and vectors of integers.
|
/// types and vectors of integers.
|
||||||
bool llvm::isPowerOfTwo(Value *V, bool OrZero, unsigned Depth) {
|
bool llvm::isKnownToBeAPowerOfTwo(Value *V, bool OrZero, unsigned Depth) {
|
||||||
if (Constant *C = dyn_cast<Constant>(V)) {
|
if (Constant *C = dyn_cast<Constant>(V)) {
|
||||||
if (C->isNullValue())
|
if (C->isNullValue())
|
||||||
return OrZero;
|
return OrZero;
|
||||||
@ -830,19 +830,19 @@ bool llvm::isPowerOfTwo(Value *V, bool OrZero, unsigned Depth) {
|
|||||||
// A shift of a power of two is a power of two or zero.
|
// A shift of a power of two is a power of two or zero.
|
||||||
if (OrZero && (match(V, m_Shl(m_Value(X), m_Value())) ||
|
if (OrZero && (match(V, m_Shl(m_Value(X), m_Value())) ||
|
||||||
match(V, m_Shr(m_Value(X), m_Value()))))
|
match(V, m_Shr(m_Value(X), m_Value()))))
|
||||||
return isPowerOfTwo(X, /*OrZero*/true, Depth);
|
return isKnownToBeAPowerOfTwo(X, /*OrZero*/true, Depth);
|
||||||
|
|
||||||
if (ZExtInst *ZI = dyn_cast<ZExtInst>(V))
|
if (ZExtInst *ZI = dyn_cast<ZExtInst>(V))
|
||||||
return isPowerOfTwo(ZI->getOperand(0), OrZero, Depth);
|
return isKnownToBeAPowerOfTwo(ZI->getOperand(0), OrZero, Depth);
|
||||||
|
|
||||||
if (SelectInst *SI = dyn_cast<SelectInst>(V))
|
if (SelectInst *SI = dyn_cast<SelectInst>(V))
|
||||||
return isPowerOfTwo(SI->getTrueValue(), OrZero, Depth) &&
|
return isKnownToBeAPowerOfTwo(SI->getTrueValue(), OrZero, Depth) &&
|
||||||
isPowerOfTwo(SI->getFalseValue(), OrZero, Depth);
|
isKnownToBeAPowerOfTwo(SI->getFalseValue(), OrZero, Depth);
|
||||||
|
|
||||||
if (OrZero && match(V, m_And(m_Value(X), m_Value(Y)))) {
|
if (OrZero && match(V, m_And(m_Value(X), m_Value(Y)))) {
|
||||||
// A power of two and'd with anything is a power of two or zero.
|
// A power of two and'd with anything is a power of two or zero.
|
||||||
if (isPowerOfTwo(X, /*OrZero*/true, Depth) ||
|
if (isKnownToBeAPowerOfTwo(X, /*OrZero*/true, Depth) ||
|
||||||
isPowerOfTwo(Y, /*OrZero*/true, Depth))
|
isKnownToBeAPowerOfTwo(Y, /*OrZero*/true, Depth))
|
||||||
return true;
|
return true;
|
||||||
// X & (-X) is always a power of two or zero.
|
// X & (-X) is always a power of two or zero.
|
||||||
if (match(X, m_Neg(m_Specific(Y))) || match(Y, m_Neg(m_Specific(X))))
|
if (match(X, m_Neg(m_Specific(Y))) || match(Y, m_Neg(m_Specific(X))))
|
||||||
@ -855,7 +855,7 @@ bool llvm::isPowerOfTwo(Value *V, bool OrZero, unsigned Depth) {
|
|||||||
// copying a sign bit (sdiv int_min, 2).
|
// copying a sign bit (sdiv int_min, 2).
|
||||||
if (match(V, m_Exact(m_LShr(m_Value(), m_Value()))) ||
|
if (match(V, m_Exact(m_LShr(m_Value(), m_Value()))) ||
|
||||||
match(V, m_Exact(m_UDiv(m_Value(), m_Value())))) {
|
match(V, m_Exact(m_UDiv(m_Value(), m_Value())))) {
|
||||||
return isPowerOfTwo(cast<Operator>(V)->getOperand(0), OrZero, Depth);
|
return isKnownToBeAPowerOfTwo(cast<Operator>(V)->getOperand(0), OrZero, Depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1027,9 +1027,9 @@ bool llvm::isKnownNonZero(Value *V, const DataLayout *TD, unsigned Depth) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The sum of a non-negative number and a power of two is not zero.
|
// The sum of a non-negative number and a power of two is not zero.
|
||||||
if (XKnownNonNegative && isPowerOfTwo(Y, /*OrZero*/false, Depth))
|
if (XKnownNonNegative && isKnownToBeAPowerOfTwo(Y, /*OrZero*/false, Depth))
|
||||||
return true;
|
return true;
|
||||||
if (YKnownNonNegative && isPowerOfTwo(X, /*OrZero*/false, Depth))
|
if (YKnownNonNegative && isKnownToBeAPowerOfTwo(X, /*OrZero*/false, Depth))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// X * Y.
|
// X * Y.
|
||||||
|
@ -37,7 +37,7 @@ static Value *simplifyValueKnownNonZero(Value *V, InstCombiner &IC) {
|
|||||||
if (match(V, m_LShr(m_OneUse(m_Shl(m_Value(PowerOf2), m_Value(A))),
|
if (match(V, m_LShr(m_OneUse(m_Shl(m_Value(PowerOf2), m_Value(A))),
|
||||||
m_Value(B))) &&
|
m_Value(B))) &&
|
||||||
// The "1" can be any value known to be a power of 2.
|
// The "1" can be any value known to be a power of 2.
|
||||||
isPowerOfTwo(PowerOf2)) {
|
isKnownToBeAPowerOfTwo(PowerOf2)) {
|
||||||
A = IC.Builder->CreateSub(A, B);
|
A = IC.Builder->CreateSub(A, B);
|
||||||
return IC.Builder->CreateShl(PowerOf2, A);
|
return IC.Builder->CreateShl(PowerOf2, A);
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ static Value *simplifyValueKnownNonZero(Value *V, InstCombiner &IC) {
|
|||||||
// (PowerOfTwo >>u B) --> isExact since shifting out the result would make it
|
// (PowerOfTwo >>u B) --> isExact since shifting out the result would make it
|
||||||
// inexact. Similarly for <<.
|
// inexact. Similarly for <<.
|
||||||
if (BinaryOperator *I = dyn_cast<BinaryOperator>(V))
|
if (BinaryOperator *I = dyn_cast<BinaryOperator>(V))
|
||||||
if (I->isLogicalShift() && isPowerOfTwo(I->getOperand(0))) {
|
if (I->isLogicalShift() && isKnownToBeAPowerOfTwo(I->getOperand(0))) {
|
||||||
// We know that this is an exact/nuw shift and that the input is a
|
// We know that this is an exact/nuw shift and that the input is a
|
||||||
// non-zero context as well.
|
// non-zero context as well.
|
||||||
if (Value *V2 = simplifyValueKnownNonZero(I->getOperand(0), IC)) {
|
if (Value *V2 = simplifyValueKnownNonZero(I->getOperand(0), IC)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user