[PATCH] D158115: [SelectionDAG][RISCV][SVE] Harden fixed offset version of ComputeValueVTs against scalable offsets.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 19 00:06:13 PDT 2023


craig.topper updated this revision to Diff 551714.
craig.topper added a comment.

Sync the zero check into getFixedValue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158115/new/

https://reviews.llvm.org/D158115

Files:
  llvm/include/llvm/Support/TypeSize.h
  llvm/lib/CodeGen/Analysis.cpp


Index: llvm/lib/CodeGen/Analysis.cpp
===================================================================
--- llvm/lib/CodeGen/Analysis.cpp
+++ llvm/lib/CodeGen/Analysis.cpp
@@ -140,15 +140,14 @@
                            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,
@@ -166,15 +165,14 @@
                            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,
Index: llvm/include/llvm/Support/TypeSize.h
===================================================================
--- llvm/include/llvm/Support/TypeSize.h
+++ llvm/include/llvm/Support/TypeSize.h
@@ -180,7 +180,7 @@
   // 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();
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158115.551714.patch
Type: text/x-patch
Size: 2389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230819/7b65fc6d/attachment.bin>


More information about the llvm-commits mailing list