[PATCH] D79202: [SVE] Fix invalid usages of getNumElements() in ValueTracking
Christopher Tetreault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 30 14:00:25 PDT 2020
ctetreau updated this revision to Diff 261341.
ctetreau added a comment.
minor stylistic changes
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79202/new/
https://reviews.llvm.org/D79202
Files:
llvm/lib/Analysis/ValueTracking.cpp
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -373,10 +373,9 @@
static unsigned ComputeNumSignBits(const Value *V, unsigned Depth,
const Query &Q) {
Type *Ty = V->getType();
+ auto *FVTy = dyn_cast<FixedVectorType>(Ty);
APInt DemandedElts =
- Ty->isVectorTy()
- ? APInt::getAllOnesValue(cast<VectorType>(Ty)->getNumElements())
- : APInt(1, 1);
+ FVTy ? APInt::getAllOnesValue(FVTy->getNumElements()) : APInt(1, 1);
return ComputeNumSignBits(V, DemandedElts, Depth, Q);
}
@@ -2638,19 +2637,19 @@
return CLow->sle(*CHigh);
}
-/// For vector constants, loop over the elements and find the constant with the
-/// minimum number of sign bits. Return 0 if the value is not a vector constant
-/// or if any element was not analyzed; otherwise, return the count for the
-/// element with the minimum number of sign bits.
-static unsigned computeNumSignBitsVectorConstant(const Value *V,
+/// For fixed width vector constants, loop over the elements and find the
+/// constant with the minimum number of sign bits. Return 0 if the value is
+/// not a vector constant or if any element was not analyzed; otherwise,
+/// return the count for the element with the minimum number of sign bits.
+static unsigned ComputeNumSignBitsVectorConstant(const Value *V,
const APInt &DemandedElts,
unsigned TyBits) {
const auto *CV = dyn_cast<Constant>(V);
- if (!CV || !CV->getType()->isVectorTy())
+ if (!CV || !isa<FixedVectorType>(CV->getType()))
return 0;
unsigned MinSignBits = TyBits;
- unsigned NumElts = cast<VectorType>(CV->getType())->getNumElements();
+ unsigned NumElts = cast<FixedVectorType>(CV->getType())->getNumElements();
for (unsigned i = 0; i != NumElts; ++i) {
if (!DemandedElts[i])
continue;
@@ -2680,9 +2679,9 @@
/// the other bits. We know that at least 1 bit is always equal to the sign bit
/// (itself), but other cases can give us information. For example, immediately
/// after an "ashr X, 2", we know that the top 3 bits are all equal to each
-/// other, so we return 3. For vectors, return the number of sign bits for the
-/// vector element with the minimum number of known sign bits of the demanded
-/// elements in the vector specified by DemandedElts.
+/// other, so we return 3. For fixed width vectors, return the number of sign
+/// bits for the vector element with the minimum number of known sign bits of
+/// the demanded elements in the vector specified by DemandedElts.
static unsigned ComputeNumSignBitsImpl(const Value *V,
const APInt &DemandedElts,
unsigned Depth, const Query &Q) {
@@ -2693,9 +2692,10 @@
// same behavior for poison though -- that's a FIXME today.
Type *Ty = V->getType();
- assert(((Ty->isVectorTy() && cast<VectorType>(Ty)->getNumElements() ==
- DemandedElts.getBitWidth()) ||
- (!Ty->isVectorTy() && DemandedElts == APInt(1, 1))) &&
+ assert(((isa<FixedVectorType>(Ty) &&
+ cast<FixedVectorType>(Ty)->getNumElements() ==
+ DemandedElts.getBitWidth()) ||
+ (!isa<FixedVectorType>(Ty) && DemandedElts == APInt(1, 1))) &&
"Unexpected vector size");
Type *ScalarTy = Ty->getScalarType();
@@ -2967,7 +2967,7 @@
// If we can examine all elements of a vector constant successfully, we're
// done (we can't do any better than that). If not, keep trying.
if (unsigned VecSignBits =
- computeNumSignBitsVectorConstant(V, DemandedElts, TyBits))
+ ComputeNumSignBitsVectorConstant(V, DemandedElts, TyBits))
return VecSignBits;
KnownBits Known(TyBits);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79202.261341.patch
Type: text/x-patch
Size: 3969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200430/9f339bf1/attachment.bin>
More information about the llvm-commits
mailing list