Skip to content

Commit

Permalink
[SelectionDAG][RISCV][SVE] Harden fixed offset version of ComputeValu…
Browse files Browse the repository at this point in the history
…eVTs against scalable offsets.

Use getFixedValue instead of getKnownMinValue to convert TypeSize
to uint64_t. I believe this would have caught the bug fixed by
D157872.

To prevent false failures, I had to treat a scalable 0 as if it
is fixed value.

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D158115
  • Loading branch information
topperc committed Aug 21, 2023
1 parent e223e45 commit e620eac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Support/TypeSize.h
Expand Up @@ -180,7 +180,7 @@ template <typename LeafTy, typename ValueTy> class FixedOrScalableQuantity {
// Use in places where a scalable count doesn't make sense (e.g. non-vector
// types, or vectors in backends which don't support scalable vectors).
constexpr ScalarTy getFixedValue() const {
assert(!isScalable() &&
assert((!isScalable() || isZero()) &&
"Request for a fixed element count on a scalable object");
return getKnownMinValue();
}
Expand Down
26 changes: 12 additions & 14 deletions llvm/lib/CodeGen/Analysis.cpp
Expand Up @@ -140,15 +140,14 @@ void llvm::ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
SmallVectorImpl<uint64_t> *FixedOffsets,
uint64_t StartingOffset) {
TypeSize Offset = TypeSize::get(StartingOffset, Ty->isScalableTy());
SmallVector<TypeSize, 4> Offsets;
if (FixedOffsets)
if (FixedOffsets) {
SmallVector<TypeSize, 4> Offsets;
ComputeValueVTs(TLI, DL, Ty, ValueVTs, &Offsets, Offset);
else
ComputeValueVTs(TLI, DL, Ty, ValueVTs, nullptr, Offset);

if (FixedOffsets)
for (TypeSize Offset : Offsets)
FixedOffsets->push_back(Offset.getKnownMinValue());
FixedOffsets->push_back(Offset.getFixedValue());
} else {
ComputeValueVTs(TLI, DL, Ty, ValueVTs, nullptr, Offset);
}
}

void llvm::ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
Expand All @@ -166,15 +165,14 @@ void llvm::ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
SmallVectorImpl<uint64_t> *FixedOffsets,
uint64_t StartingOffset) {
TypeSize Offset = TypeSize::get(StartingOffset, Ty->isScalableTy());
SmallVector<TypeSize, 4> Offsets;
if (FixedOffsets)
if (FixedOffsets) {
SmallVector<TypeSize, 4> Offsets;
ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, &Offsets, Offset);
else
ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, nullptr, Offset);

if (FixedOffsets)
for (TypeSize Offset : Offsets)
FixedOffsets->push_back(Offset.getKnownMinValue());
FixedOffsets->push_back(Offset.getFixedValue());
} else {
ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, nullptr, Offset);
}
}

void llvm::computeValueLLTs(const DataLayout &DL, Type &Ty,
Expand Down

0 comments on commit e620eac

Please sign in to comment.