[PATCH] D136517: [InstCombine] Explicitly check for scalable TypeSize.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 21 17:49:34 PDT 2022


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

clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136517

Files:
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/test/Transforms/InstCombine/gep-object-size-less-than-or-equal-typesize.ll


Index: llvm/test/Transforms/InstCombine/gep-object-size-less-than-or-equal-typesize.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/gep-object-size-less-than-or-equal-typesize.ll
@@ -0,0 +1,17 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -instcombine -S | FileCheck %s
+
+define i8 @foo(<vscale x 1 x i8> %x, i64 %idx) {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:    [[A:%.*]] = alloca <vscale x 1 x i8>, align 1
+; CHECK-NEXT:    store <vscale x 1 x i8> [[X:%.*]], ptr [[A]], align 1
+; CHECK-NEXT:    [[B:%.*]] = getelementptr i8, ptr [[A]], i64 [[IDX:%.*]]
+; CHECK-NEXT:    [[C:%.*]] = load i8, ptr [[B]], align 1
+; CHECK-NEXT:    ret i8 [[C]]
+;
+  %a = alloca <vscale x 1 x i8>
+  store <vscale x 1 x i8> %x, ptr %a
+  %b = getelementptr i8, ptr %a, i64 %idx
+  %c = load i8, ptr %b
+  ret i8 %c
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -769,10 +769,13 @@
       if (!CS)
         return false;
 
-      uint64_t TypeSize = DL.getTypeAllocSize(AI->getAllocatedType());
+      TypeSize TS = DL.getTypeAllocSize(AI->getAllocatedType());
+      if (TS.isScalable())
+        return false;
       // Make sure that, even if the multiplication below would wrap as an
       // uint64_t, we still do the right thing.
-      if ((CS->getValue().zext(128) * APInt(128, TypeSize)).ugt(MaxSize))
+      if ((CS->getValue().zext(128) * APInt(128, TS.getFixedSize()))
+              .ugt(MaxSize))
         return false;
       continue;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136517.469835.patch
Type: text/x-patch
Size: 1790 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221022/c118aae9/attachment.bin>


More information about the llvm-commits mailing list