[llvm] a400aa5 - [SVE] Fix getAlignmentInfo for scalable vectors

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 23:53:04 PDT 2020


Author: David Sherwood
Date: 2020-05-07T07:52:37+01:00
New Revision: a400aa5faf7811c4ff719c312e03b8bd7543f8bf

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

LOG: [SVE] Fix getAlignmentInfo for scalable vectors

When calculating the natural alignment for scalable vectors it
is acceptable to calculate an allocation size based on the minimum
number of elements in the vector.

This code path is exercised by an existing test:

  CodeGen/AArch64/sve-intrinsics-int-arith.ll

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

Added: 
    

Modified: 
    llvm/lib/IR/DataLayout.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index cb5038992cf8..0a25f1c14da0 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -559,7 +559,10 @@ Align DataLayout::getAlignmentInfo(AlignTypeEnum AlignType, uint32_t BitWidth,
     // with what clang and llvm-gcc do.
     unsigned Alignment =
         getTypeAllocSize(cast<VectorType>(Ty)->getElementType());
-    Alignment *= cast<VectorType>(Ty)->getNumElements();
+    // We're only calculating a natural alignment, so it doesn't have to be
+    // based on the full size for scalable vectors. Using the minimum element
+    // count should be enough here.
+    Alignment *= cast<VectorType>(Ty)->getElementCount().Min;
     Alignment = PowerOf2Ceil(Alignment);
     return Align(Alignment);
    }


        


More information about the llvm-commits mailing list