Skip to content

Commit 8002fa6

Browse files
committed
[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
1 parent 10a356c commit 8002fa6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

llvm/docs/LangRef.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,10 +2680,6 @@ following rules:
26802680
given the default specifications above, the i7 type will use the
26812681
alignment of i8 (next largest) while both i65 and i256 will use the
26822682
alignment of i64 (largest specified).
2683-
#. If no match is found, and the type sought is a vector type, then the
2684-
largest vector type that is smaller than the sought vector type will
2685-
be used as a fall back. This happens because <128 x double> can be
2686-
implemented in terms of 64 <2 x double>, for example.
26872683

26882684
The function of the data layout string may not be what you expect.
26892685
Notably, this is not a specification from the frontend of what alignment

llvm/unittests/IR/DataLayoutTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "llvm/IR/LLVMContext.h"
1212
#include "llvm/IR/Module.h"
1313
#include "llvm/IR/Type.h"
14+
#include "llvm/Testing/Support/Error.h"
1415
#include "gtest/gtest.h"
1516

1617
using namespace llvm;
@@ -89,4 +90,18 @@ TEST(DataLayoutTest, GlobalsAddressSpace) {
8990
EXPECT_EQ(ExplicitGlobal2->getAddressSpace(), 123u);
9091
}
9192

93+
TEST(DataLayoutTest, VectorAlign) {
94+
Expected<DataLayout> DL = DataLayout::parse("v64:64");
95+
EXPECT_THAT_EXPECTED(DL, Succeeded());
96+
97+
LLVMContext Context;
98+
Type *const FloatTy = Type::getFloatTy(Context);
99+
Type *const V8F32Ty = FixedVectorType::get(FloatTy, 8);
100+
101+
// The alignment for a vector type larger than any specified vector type uses
102+
// the natural alignment as a fallback.
103+
EXPECT_EQ(Align(4 * 8), DL->getABITypeAlign(V8F32Ty));
104+
EXPECT_EQ(Align(4 * 8), DL->getPrefTypeAlign(V8F32Ty));
105+
}
106+
92107
} // anonymous namespace

0 commit comments

Comments
 (0)