[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
Wed Aug 16 13:43:29 PDT 2023


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

Add the whole patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158115

Files:
  llvm/lib/CodeGen/Analysis.cpp


Index: llvm/lib/CodeGen/Analysis.cpp
===================================================================
--- llvm/lib/CodeGen/Analysis.cpp
+++ llvm/lib/CodeGen/Analysis.cpp
@@ -141,14 +141,17 @@
                            uint64_t StartingOffset) {
   TypeSize Offset = TypeSize::get(StartingOffset, Ty->isScalableTy());
   SmallVector<TypeSize, 4> Offsets;
-  if (FixedOffsets)
+  if (FixedOffsets) {
     ComputeValueVTs(TLI, DL, Ty, ValueVTs, &Offsets, Offset);
-  else
+    for (TypeSize Offset : Offsets) {
+      // Treat scalable zero as if it is fixed. Otherwise use getFixedValued
+      // to get an assert for scalable offsets.
+      FixedOffsets->push_back(Offset.isZero() ? Offset.getKnownMinValue()
+                                              : Offset.getFixedValue());
+    }
+  } else {
     ComputeValueVTs(TLI, DL, Ty, ValueVTs, nullptr, Offset);
-
-  if (FixedOffsets)
-    for (TypeSize Offset : Offsets)
-      FixedOffsets->push_back(Offset.getKnownMinValue());
+  }
 }
 
 void llvm::ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
@@ -167,14 +170,17 @@
                            uint64_t StartingOffset) {
   TypeSize Offset = TypeSize::get(StartingOffset, Ty->isScalableTy());
   SmallVector<TypeSize, 4> Offsets;
-  if (FixedOffsets)
+  if (FixedOffsets) {
     ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, &Offsets, Offset);
-  else
+    for (TypeSize Offset : Offsets) {
+      // Treat scalable zero as if it is fixed. Otherwise use getFixedValued
+      // to get an assert for scalable offsets.
+      FixedOffsets->push_back(Offset.isZero() ? Offset.getKnownMinValue()
+                                              : Offset.getFixedValue());
+    }
+  } else {
     ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, nullptr, Offset);
-
-  if (FixedOffsets)
-    for (TypeSize Offset : Offsets)
-      FixedOffsets->push_back(Offset.getKnownMinValue());
+  }
 }
 
 void llvm::computeValueLLTs(const DataLayout &DL, Type &Ty,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158115.550870.patch
Type: text/x-patch
Size: 1979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230816/039bab99/attachment.bin>


More information about the llvm-commits mailing list