[llvm] 1edc51b - [InstCombine] Explicitly check for scalable TypeSize.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 24 12:29:23 PDT 2022


Author: Craig Topper
Date: 2022-10-24T12:29:06-07:00
New Revision: 1edc51b56a0c27db5561d7bb117918f88c28780a

URL: https://github.com/llvm/llvm-project/commit/1edc51b56a0c27db5561d7bb117918f88c28780a
DIFF: https://github.com/llvm/llvm-project/commit/1edc51b56a0c27db5561d7bb117918f88c28780a.diff

LOG: [InstCombine] Explicitly check for scalable TypeSize.

Instead of assuming it is a fixed size.

Reviewed By: peterwaller-arm

Differential Revision: https://reviews.llvm.org/D136517

Added: 
    llvm/test/Transforms/InstCombine/gep-object-size-less-than-or-equal-typesize.ll

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index d14583231082..a1f29cb69efc 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -769,10 +769,13 @@ static bool isObjectSizeLessThanOrEq(Value *V, uint64_t MaxSize,
       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;
     }

diff  --git a/llvm/test/Transforms/InstCombine/gep-object-size-less-than-or-equal-typesize.ll b/llvm/test/Transforms/InstCombine/gep-object-size-less-than-or-equal-typesize.ll
new file mode 100644
index 000000000000..2bcf8f06b81a
--- /dev/null
+++ b/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 %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
+}


        


More information about the llvm-commits mailing list