[PATCH] D134032: [SROA] Check typeSizeEqualsStoreSize in isVectorPromotionViable

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 16 06:03:02 PDT 2022


bjope created this revision.
bjope added reviewers: MatzeB, efriedma, A-Wadhwani.
Herald added subscribers: ctetreau, hiraditya, tschuett.
Herald added a project: All.
bjope requested review of this revision.
Herald added a project: LLVM.

Commit de3445e0ef15c4209 <https://reviews.llvm.org/rGde3445e0ef15c420955ad720fccf08473f460443> (https://reviews.llvm.org/D132096) made
changes to isVectorPromotionViable basically doing

  // Create Vector with size of V, and each element of type Ty
  ...
  uint64_t ElementSize = DL.getTypeStoreSizeInBits(Ty).getFixedSize();
  uint64_t VectorSize = DL.getTypeSizeInBits(V).getFixedSize();
  ...
  VectorType *VTy = VectorType::get(Ty, VectorSize / ElementSize, false);

Not quite sure why it uses the TypeStoreSize for the ElementSize,
but the new vector would only match in size with the old vector in
situations when the TypeStoreSize equals the TypeSize for Ty.
Therefore this patch adds a typeSizeEqualsStoreSize check as yet
another condition for allowing the the new type as a promotion
candidate.

Without this fix the new @test15 test would fail with an assert
like this:

opt: ../lib/Transforms/Scalar/SROA.cpp:1966:

  auto isVectorPromotionViable(llvm::sroa::Partition &,
                               const llvm::DataLayout &)
       ::(anonymous class)::operator()(llvm::VectorType *,
                                       llvm::VectorType *) const:
  Assertion `DL.getTypeSizeInBits(RHSTy).getFixedSize() ==
             DL.getTypeSizeInBits(LHSTy).getFixedSize() &&
             "Cannot have vector types of different sizes!"' failed.

...
 #8  isVectorPromotionViable(...)::$_10::operator()...
 #9  llvm::SROAPass::rewritePartition(...)
#10  llvm::SROAPass::splitAlloca(...)
#11  llvm::SROAPass::runOnAlloca(...)
#12  llvm::SROAPass::runImpl(...)
#13  llvm::SROAPass::run(...)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134032

Files:
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/test/Transforms/SROA/vector-promotion.ll


Index: llvm/test/Transforms/SROA/vector-promotion.ll
===================================================================
--- llvm/test/Transforms/SROA/vector-promotion.ll
+++ llvm/test/Transforms/SROA/vector-promotion.ll
@@ -628,3 +628,13 @@
   %add2 = add i32 %add, %add1
   ret i32 %add2
 }
+
+; This used to hit an assert after commit de3445e0ef15c4.
+; Added as regression test to verify that we handle this without crashing.
+define i1 @test15() {
+  %a = alloca <8 x i32>
+  store <2 x i64> <i64 0, i64 -1>, ptr %a
+  %l = load i1, ptr %a, align 1
+  ret i1 %l
+
+}
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1933,6 +1933,8 @@
       continue;
     if (isa<VectorType>(Ty))
       continue;
+    if (!DL.typeSizeEqualsStoreSize(Ty))
+      continue;
     // Create Vector with size of V, and each element of type Ty
     VectorType *V = CandidateTys[0];
     uint64_t ElementSize = DL.getTypeStoreSizeInBits(Ty).getFixedSize();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134032.460714.patch
Type: text/x-patch
Size: 1086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220916/8176bb3d/attachment.bin>


More information about the llvm-commits mailing list