[llvm] 8002fa6 - [LangRef] Remove incorrect vector alignment rules

Fraser Cormack via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 14 06:45:13 PST 2021


Author: Fraser Cormack
Date: 2021-12-14T14:35:40Z
New Revision: 8002fa67603b4e2fa7384bb0bbad2a649252271f

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

LOG: [LangRef] Remove incorrect vector alignment rules

The LangRef incorrectly says that if no exact match is found when
seeking alignment for a vector type, the largest vector type smaller
than the sought-after vector type. This is incorrect as vector types
require an exact match, else they fall back to reporting the natural
alignment.

The corrected rule was not added in its place, as rules for other types
(e.g., floating-point types) aren't documented.

A unit test was added to demonstrate this.

Reviewed By: aeubanks

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

Added: 
    

Modified: 
    llvm/docs/LangRef.rst
    llvm/unittests/IR/DataLayoutTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 55cfba884712e..7977b3b9fd4e8 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2680,10 +2680,6 @@ following rules:
    given the default specifications above, the i7 type will use the
    alignment of i8 (next largest) while both i65 and i256 will use the
    alignment of i64 (largest specified).
-#. If no match is found, and the type sought is a vector type, then the
-   largest vector type that is smaller than the sought vector type will
-   be used as a fall back. This happens because <128 x double> can be
-   implemented in terms of 64 <2 x double>, for example.
 
 The function of the data layout string may not be what you expect.
 Notably, this is not a specification from the frontend of what alignment

diff  --git a/llvm/unittests/IR/DataLayoutTest.cpp b/llvm/unittests/IR/DataLayoutTest.cpp
index 3f860c8eaad1c..b9fc2172b7bf2 100644
--- a/llvm/unittests/IR/DataLayoutTest.cpp
+++ b/llvm/unittests/IR/DataLayoutTest.cpp
@@ -11,6 +11,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -89,4 +90,18 @@ TEST(DataLayoutTest, GlobalsAddressSpace) {
   EXPECT_EQ(ExplicitGlobal2->getAddressSpace(), 123u);
 }
 
+TEST(DataLayoutTest, VectorAlign) {
+  Expected<DataLayout> DL = DataLayout::parse("v64:64");
+  EXPECT_THAT_EXPECTED(DL, Succeeded());
+
+  LLVMContext Context;
+  Type *const FloatTy = Type::getFloatTy(Context);
+  Type *const V8F32Ty = FixedVectorType::get(FloatTy, 8);
+
+  // The alignment for a vector type larger than any specified vector type uses
+  // the natural alignment as a fallback.
+  EXPECT_EQ(Align(4 * 8), DL->getABITypeAlign(V8F32Ty));
+  EXPECT_EQ(Align(4 * 8), DL->getPrefTypeAlign(V8F32Ty));
+}
+
 } // anonymous namespace


        


More information about the llvm-commits mailing list