1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

[ValueTracking] Clarify TypeSize comparisons

TypeSize comparisons using overloaded operators should be replaced by
the new isKnownXY comparators when the operands can be fixed-length or
scalable vectors.

In ValueTracking there are several uses of the overloaded operators in
`isKnownNonZero` and `ComputeMultiple`. In the former we already bail
out on scalable vectors since we currently have no way to represent
DemandedElts, and the latter is operating on scalar integers, so we can
assume fixed-size in both instances.

Reviewed By: david-arm

Differential Revision: https://reviews.llvm.org/D89387
This commit is contained in:
Cullen Rhodes 2020-10-13 12:26:47 +00:00
parent a8146af1a9
commit 8ce9e66236

View File

@ -2256,8 +2256,9 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
// See the comment for IntToPtr/PtrToInt instructions below. // See the comment for IntToPtr/PtrToInt instructions below.
if (CE->getOpcode() == Instruction::IntToPtr || if (CE->getOpcode() == Instruction::IntToPtr ||
CE->getOpcode() == Instruction::PtrToInt) CE->getOpcode() == Instruction::PtrToInt)
if (Q.DL.getTypeSizeInBits(CE->getOperand(0)->getType()) <= if (Q.DL.getTypeSizeInBits(CE->getOperand(0)->getType())
Q.DL.getTypeSizeInBits(CE->getType())) .getFixedSize() <=
Q.DL.getTypeSizeInBits(CE->getType()).getFixedSize())
return isKnownNonZero(CE->getOperand(0), Depth, Q); return isKnownNonZero(CE->getOperand(0), Depth, Q);
} }
@ -2354,16 +2355,16 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
return isKnownNonZero(BCO->getOperand(0), Depth, Q); return isKnownNonZero(BCO->getOperand(0), Depth, Q);
if (auto *I2P = dyn_cast<IntToPtrInst>(V)) if (auto *I2P = dyn_cast<IntToPtrInst>(V))
if (Q.DL.getTypeSizeInBits(I2P->getSrcTy()) <= if (Q.DL.getTypeSizeInBits(I2P->getSrcTy()).getFixedSize() <=
Q.DL.getTypeSizeInBits(I2P->getDestTy())) Q.DL.getTypeSizeInBits(I2P->getDestTy()).getFixedSize())
return isKnownNonZero(I2P->getOperand(0), Depth, Q); return isKnownNonZero(I2P->getOperand(0), Depth, Q);
} }
// Similar to int2ptr above, we can look through ptr2int here if the cast // Similar to int2ptr above, we can look through ptr2int here if the cast
// is a no-op or an extend and not a truncate. // is a no-op or an extend and not a truncate.
if (auto *P2I = dyn_cast<PtrToIntInst>(V)) if (auto *P2I = dyn_cast<PtrToIntInst>(V))
if (Q.DL.getTypeSizeInBits(P2I->getSrcTy()) <= if (Q.DL.getTypeSizeInBits(P2I->getSrcTy()).getFixedSize() <=
Q.DL.getTypeSizeInBits(P2I->getDestTy())) Q.DL.getTypeSizeInBits(P2I->getDestTy()).getFixedSize())
return isKnownNonZero(P2I->getOperand(0), Depth, Q); return isKnownNonZero(P2I->getOperand(0), Depth, Q);
unsigned BitWidth = getBitWidth(V->getType()->getScalarType(), Q.DL); unsigned BitWidth = getBitWidth(V->getType()->getScalarType(), Q.DL);
@ -3059,11 +3060,11 @@ bool llvm::ComputeMultiple(Value *V, unsigned Base, Value *&Multiple,
if (ComputeMultiple(Op0, Base, Mul0, LookThroughSExt, Depth+1)) { if (ComputeMultiple(Op0, Base, Mul0, LookThroughSExt, Depth+1)) {
if (Constant *Op1C = dyn_cast<Constant>(Op1)) if (Constant *Op1C = dyn_cast<Constant>(Op1))
if (Constant *MulC = dyn_cast<Constant>(Mul0)) { if (Constant *MulC = dyn_cast<Constant>(Mul0)) {
if (Op1C->getType()->getPrimitiveSizeInBits() < if (Op1C->getType()->getPrimitiveSizeInBits().getFixedSize() <
MulC->getType()->getPrimitiveSizeInBits()) MulC->getType()->getPrimitiveSizeInBits().getFixedSize())
Op1C = ConstantExpr::getZExt(Op1C, MulC->getType()); Op1C = ConstantExpr::getZExt(Op1C, MulC->getType());
if (Op1C->getType()->getPrimitiveSizeInBits() > if (Op1C->getType()->getPrimitiveSizeInBits().getFixedSize() >
MulC->getType()->getPrimitiveSizeInBits()) MulC->getType()->getPrimitiveSizeInBits().getFixedSize())
MulC = ConstantExpr::getZExt(MulC, Op1C->getType()); MulC = ConstantExpr::getZExt(MulC, Op1C->getType());
// V == Base * (Mul0 * Op1), so return (Mul0 * Op1) // V == Base * (Mul0 * Op1), so return (Mul0 * Op1)
@ -3083,11 +3084,11 @@ bool llvm::ComputeMultiple(Value *V, unsigned Base, Value *&Multiple,
if (ComputeMultiple(Op1, Base, Mul1, LookThroughSExt, Depth+1)) { if (ComputeMultiple(Op1, Base, Mul1, LookThroughSExt, Depth+1)) {
if (Constant *Op0C = dyn_cast<Constant>(Op0)) if (Constant *Op0C = dyn_cast<Constant>(Op0))
if (Constant *MulC = dyn_cast<Constant>(Mul1)) { if (Constant *MulC = dyn_cast<Constant>(Mul1)) {
if (Op0C->getType()->getPrimitiveSizeInBits() < if (Op0C->getType()->getPrimitiveSizeInBits().getFixedSize() <
MulC->getType()->getPrimitiveSizeInBits()) MulC->getType()->getPrimitiveSizeInBits().getFixedSize())
Op0C = ConstantExpr::getZExt(Op0C, MulC->getType()); Op0C = ConstantExpr::getZExt(Op0C, MulC->getType());
if (Op0C->getType()->getPrimitiveSizeInBits() > if (Op0C->getType()->getPrimitiveSizeInBits().getFixedSize() >
MulC->getType()->getPrimitiveSizeInBits()) MulC->getType()->getPrimitiveSizeInBits().getFixedSize())
MulC = ConstantExpr::getZExt(MulC, Op0C->getType()); MulC = ConstantExpr::getZExt(MulC, Op0C->getType());
// V == Base * (Mul1 * Op0), so return (Mul1 * Op0) // V == Base * (Mul1 * Op0), so return (Mul1 * Op0)