[PATCH] D76386: [InstCombine][SVE] Fix InstCombiner::visitAllocaInst for scalable vector.

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 18 21:09:59 PDT 2020


This revision was automatically updated to reflect the committed changes.
huihuiz marked an inline comment as done.
Closed by commit rG2ea5495759f6: [InstCombine][SVE] Fix InstCombiner::visitAllocaInst for scalable vector. (authored by huihuiz).

Changed prior to commit:
  https://reviews.llvm.org/D76386?vs=251172&id=251264#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76386

Files:
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/test/Transforms/InstCombine/vscale_alloca.ll


Index: llvm/test/Transforms/InstCombine/vscale_alloca.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/vscale_alloca.ll
@@ -0,0 +1,37 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -instcombine -verify < %s | FileCheck %s
+
+define <vscale x 4 x i32> @alloca(<vscale x 4 x i32> %z) {
+; CHECK-LABEL: @alloca(
+; CHECK-NEXT:    ret <vscale x 4 x i32> [[Z:%.*]]
+;
+  %a = alloca <vscale x 4 x i32>
+  store <vscale x 4 x i32> %z, <vscale x 4 x i32>* %a
+  %load = load <vscale x 4 x i32>, <vscale x 4 x i32>* %a
+  ret <vscale x 4 x i32> %load
+}
+
+define void @alloca_dead_store(<vscale x 4 x i32> %z) {
+; CHECK-LABEL: @alloca_dead_store(
+; CHECK-NEXT:    ret void
+;
+  %a = alloca <vscale x 4 x i32>
+  store <vscale x 4 x i32> %z, <vscale x 4 x i32>* %a
+  ret void
+}
+
+declare void @use(...)
+define void @alloca_zero_byte_move_first_inst() {
+; CHECK-LABEL: @alloca_zero_byte_move_first_inst(
+; CHECK-NEXT:    [[B:%.*]] = alloca {}, align 8
+; CHECK-NEXT:    [[A:%.*]] = alloca <vscale x 16 x i8>, align 16
+; CHECK-NEXT:    call void (...) @use(<vscale x 16 x i8>* nonnull [[A]])
+; CHECK-NEXT:    call void (...) @use({}* nonnull [[B]])
+; CHECK-NEXT:    ret void
+;
+  %a = alloca <vscale x 16 x i8>
+  call void (...) @use( <vscale x 16 x i8>* %a )
+  %b = alloca {  }
+  call void (...) @use( {  }* %b )
+  ret void
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -348,7 +348,7 @@
     // Move all alloca's of zero byte objects to the entry block and merge them
     // together.  Note that we only do this for alloca's, because malloc should
     // allocate and return a unique pointer, even for a zero byte allocation.
-    if (DL.getTypeAllocSize(AI.getAllocatedType()) == 0) {
+    if (DL.getTypeAllocSize(AI.getAllocatedType()).getKnownMinSize() == 0) {
       // For a zero sized alloca there is no point in doing an array allocation.
       // This is helpful if the array size is a complicated expression not used
       // elsewhere.
@@ -365,7 +365,8 @@
         // dominance as the array size was forced to a constant earlier already.
         AllocaInst *EntryAI = dyn_cast<AllocaInst>(FirstInst);
         if (!EntryAI || !EntryAI->getAllocatedType()->isSized() ||
-            DL.getTypeAllocSize(EntryAI->getAllocatedType()) != 0) {
+            DL.getTypeAllocSize(EntryAI->getAllocatedType())
+                    .getKnownMinSize() != 0) {
           AI.moveBefore(FirstInst);
           return &AI;
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76386.251264.patch
Type: text/x-patch
Size: 2794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200319/4c1ab9a9/attachment.bin>


More information about the llvm-commits mailing list