Skip to content

Commit

Permalink
The maximal representable alignment in LLVM IR is 1GiB, not 512MiB
Browse files Browse the repository at this point in the history
In LLVM IR, `AlignmentBitfieldElementT` is 5-bit wide
But that means that the maximal alignment exponent is `(1<<5)-2`,
which is `30`, not `29`. And indeed, alignment of `1073741824`
roundtrips IR serialization-deserialization.

While this doesn't seem all that important, this doubles
the maximal supported alignment from 512MiB to 1GiB,
and there's actually one noticeable use-case for that;
On X86, the huge pages can have sizes of 2MiB and 1GiB (!).

So while this doesn't add support for truly huge alignments,
which i think we can easily-ish do if wanted, i think this adds
zero-cost support for a not-trivially-dismissable case.

I don't believe we need any upgrade infrastructure,
and since we don't explicitly record the IR version,
we don't need to bump one either.

As @craig.topper speculates in D108661#2963519,
this might be an artificial limit imposed by the original implementation
of the `getAlignment()` functions.

Differential Revision: https://reviews.llvm.org/D108661
  • Loading branch information
LebedevRI committed Aug 26, 2021
1 parent 5ece556 commit 564d85e
Show file tree
Hide file tree
Showing 42 changed files with 184 additions and 138 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class Sema final {
///
/// This is the greatest alignment value supported by load, store, and alloca
/// instructions, and global values.
static const unsigned MaxAlignmentExponent = 29;
static const unsigned MaxAlignmentExponent = 30;
static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent;

typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
Expand Down
8 changes: 5 additions & 3 deletions clang/test/CXX/drs/dr6xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,11 @@ namespace dr648 { // dr648: yes

#if __cplusplus >= 201103L
namespace dr649 { // dr649: yes
alignas(0x40000000) int n; // expected-error {{requested alignment}}1
struct alignas(0x40000000) X {}; // expected-error {{requested alignment}}
struct Y { int n alignas(0x40000000); }; // expected-error {{requested alignment}}
alignas(0x80000000) int n; // expected-error {{requested alignment}}1
struct alignas(0x80000000) X {}; // expected-error {{requested alignment}}
struct Y {
int n alignas(0x80000000); // expected-error {{requested alignment}}
};
struct alignas(256) Z {};
// This part is superseded by dr2130 and eventually by aligned allocation support.
auto *p = new Z;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/builtin-assume-aligned.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int test6() {
// CHECK-NEXT: store i32* [[A]], i32** [[A_ADDR]], align 8
// CHECK-NEXT: [[TMP0:%.*]] = load i32*, i32** [[A_ADDR]], align 8
// CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[TMP0]] to i8*
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* [[TMP1]], i64 536870912) ]
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* [[TMP1]], i64 1073741824) ]
// CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i32*
// CHECK-NEXT: store i32* [[TMP2]], i32** [[A_ADDR]], align 8
// CHECK-NEXT: [[TMP3:%.*]] = load i32*, i32** [[A_ADDR]], align 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// CHECK-SANITIZE-ANYRECOVER: @[[LINE_100_ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 100, i32 10 }, {{.*}}* @[[CHAR]] }

char **passthrough(__attribute__((align_value(0x80000000))) char **x) {
// CHECK-NOSANITIZE: define{{.*}} i8** @{{.*}}(i8** align 536870912 %[[X:.*]])
// CHECK-NOSANITIZE: define{{.*}} i8** @{{.*}}(i8** align 1073741824 %[[X:.*]])
// CHECK-SANITIZE: define{{.*}} i8** @{{.*}}(i8** %[[X:.*]])
// CHECK-NEXT: [[entry:.*]]:
// CHECK-NEXT: %[[X_ADDR:.*]] = alloca i8**, align 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ void *caller(char **x, unsigned long offset) {
// CHECK-NEXT: %[[OFFSET_RELOADED:.*]] = load i64, i64* %[[OFFSET_ADDR]], align 8
// CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[BITCAST]] to i64
// CHECK-SANITIZE-NEXT: %[[OFFSETPTR:.*]] = sub i64 %[[PTRINT]], %[[OFFSET_RELOADED]]
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 536870911
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 1073741823
// CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
// CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[BITCAST]] to i64, !nosanitize
// CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
// CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 536870912, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 536870912, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize
// CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
// CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
// CHECK-SANITIZE: [[CONT]]:
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 536870912, i64 %[[OFFSET_RELOADED]]) ]
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 1073741824, i64 %[[OFFSET_RELOADED]]) ]
// CHECK-NEXT: ret i8* %[[BITCAST]]
// CHECK-NEXT: }
#line 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ void *caller(char **x) {
// CHECK-NEXT: %[[BITCAST:.*]] = bitcast i8** %[[X_RELOADED]] to i8*
// CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[BITCAST]] to i64
// CHECK-SANITIZE-NEXT: %[[OFFSETPTR:.*]] = sub i64 %[[PTRINT]], 42
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 536870911
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 1073741823
// CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
// CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[BITCAST]] to i64, !nosanitize
// CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
// CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 536870912, i64 42){{.*}}, !nosanitize
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 536870912, i64 42){{.*}}, !nosanitize
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 42){{.*}}, !nosanitize
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 42){{.*}}, !nosanitize
// CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
// CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
// CHECK-SANITIZE: [[CONT]]:
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 536870912, i64 42) ]
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 1073741824, i64 42) ]
// CHECK-NEXT: ret i8* %[[BITCAST]]
// CHECK-NEXT: }
#line 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ void *caller(char **x) {
// CHECK-NEXT: %[[X_RELOADED:.*]] = load i8**, i8*** %[[X_ADDR]], align 8
// CHECK-NEXT: %[[BITCAST:.*]] = bitcast i8** %[[X_RELOADED]] to i8*
// CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[BITCAST]] to i64
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 536870911
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 1073741823
// CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
// CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[BITCAST]] to i64, !nosanitize
// CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
// CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 536870912, i64 0){{.*}}, !nosanitize
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 536870912, i64 0){{.*}}, !nosanitize
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 0){{.*}}, !nosanitize
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 0){{.*}}, !nosanitize
// CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
// CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
// CHECK-SANITIZE: [[CONT]]:
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 536870912) ]
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 1073741824) ]
// CHECK-NEXT: ret i8* %[[BITCAST]]
// CHECK-NEXT: }
#line 100
Expand Down
10 changes: 5 additions & 5 deletions clang/test/CodeGen/catch-alignment-assumption-openmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ void func(char *data) {
// CHECK: store i8* %[[DATA]], i8** %[[DATA_ADDR]], align 8
// CHECK: %[[DATA_RELOADED:.*]] = load i8*, i8** %[[DATA_ADDR]], align 8
// CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[DATA_RELOADED]] to i64
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 1073741823
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 2147483647
// CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
// CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[DATA_RELOADED]] to i64, !nosanitize
// CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
// CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 0){{.*}}, !nosanitize
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 0){{.*}}, !nosanitize
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 0){{.*}}, !nosanitize
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 0){{.*}}, !nosanitize
// CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
// CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
// CHECK-SANITIZE: [[CONT]]:
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[DATA_RELOADED]], i64 1073741824) ]
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[DATA_RELOADED]], i64 2147483648) ]

#line 100
#pragma omp for simd aligned(data : 0x40000000)
#pragma omp for simd aligned(data : 0x80000000)
for (int x = 0; x < 1; x++)
data[x] = data[x];
}
6 changes: 3 additions & 3 deletions clang/test/Sema/alloc-align-attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// return values
void test_void_alloc_align(void) __attribute__((alloc_align(1))); // expected-warning {{'alloc_align' attribute only applies to return values that are pointers}}
void *test_ptr_alloc_align(int a) __attribute__((alloc_align(1))); // no-warning
void *test_ptr_alloc_align(unsigned int a) __attribute__((alloc_align(1))); // no-warning

int j __attribute__((alloc_align(1))); // expected-warning {{'alloc_align' attribute only applies to non-K&R-style functions}}
void *test_no_params_zero(void) __attribute__((alloc_align(0))); // expected-error {{'alloc_align' attribute parameter 1 is out of bounds}}
Expand All @@ -26,6 +26,6 @@ void *align16() {
void *align15() {
return test_ptr_alloc_align(15); // expected-warning {{requested alignment is not a power of 2}}
}
void *align536870912() {
return test_ptr_alloc_align(1073741824); // expected-warning {{requested alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
void *align1073741824() {
return test_ptr_alloc_align(2147483648); // expected-warning {{requested alignment must be 1073741824 bytes or smaller; maximum alignment assumed}}
}
2 changes: 1 addition & 1 deletion clang/test/Sema/attr-aligned.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s

int x __attribute__((aligned(3))); // expected-error {{requested alignment is not a power of 2}}
int y __attribute__((aligned(1 << 30))); // expected-error {{requested alignment must be 536870912 bytes or smaller}}
int y __attribute__((aligned(1 << 31))); // expected-error {{requested alignment must be 1073741824 bytes or smaller}}

// PR26444
int y __attribute__((aligned(1 << 29)));
Expand Down
6 changes: 3 additions & 3 deletions clang/test/Sema/builtin-assume-aligned.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int test8(int *a, int j) {
void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(1073741824))); // expected-warning {{requested alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(2147483648))); // expected-warning {{requested alignment must be 1073741824 bytes or smaller; maximum alignment assumed}}

int j __attribute__((assume_aligned(8))); // expected-warning {{'assume_aligned' attribute only applies to Objective-C methods and functions}}
void *test_no_fn_proto() __attribute__((assume_aligned(32))); // no-warning
Expand All @@ -60,6 +60,6 @@ void *test_no_fn_proto() __attribute__((assume_aligned())); // expected-error {{
void *test_no_fn_proto() __attribute__((assume_aligned(32, 45, 37))); // expected-error {{'assume_aligned' attribute takes no more than 2 arguments}}

int pr43638(int *a) {
a = __builtin_assume_aligned(a, 1073741824); // expected-warning {{requested alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
return a[0];
a = __builtin_assume_aligned(a, 2147483648); // expected-warning {{requested alignment must be 1073741824 bytes or smaller; maximum alignment assumed}}
return a[0];
}
8 changes: 4 additions & 4 deletions clang/test/SemaCXX/alloc-align-attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ struct param_num {

template <typename T>
struct dependent_ret {
T* Foo(int a) __attribute__((alloc_align(2)));// no-warning, ends up being int**.
T Foo2(int a) __attribute__((alloc_align(2)));// expected-warning {{'alloc_align' attribute only applies to return values that are pointers or references}}
T *Foo(unsigned a) __attribute__((alloc_align(2))); // no-warning, ends up being int**.
T Foo2(unsigned a) __attribute__((alloc_align(2))); // expected-warning {{'alloc_align' attribute only applies to return values that are pointers or references}}
};

// Following 2 errors associated only with the 'float' versions below.
Expand All @@ -32,8 +32,8 @@ void dependent_impl(int align) {
b.Foo2(1);
b.Foo(3); // expected-warning {{requested alignment is not a power of 2}}
b.Foo2(3); // expected-warning {{requested alignment is not a power of 2}}
b.Foo(1073741824); // expected-warning {{requested alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
b.Foo2(1073741824); // expected-warning {{requested alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
b.Foo(2147483648); // expected-warning {{requested alignment must be 1073741824 bytes or smaller; maximum alignment assumed}}
b.Foo2(2147483648); // expected-warning {{requested alignment must be 1073741824 bytes or smaller; maximum alignment assumed}}
b.Foo(align);
b.Foo2(align);

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Instruction : public User,
// Template alias so that all Instruction storing alignment use the same
// definiton.
// Valid alignments are powers of two from 2^0 to 2^MaxAlignmentExponent =
// 2^29. We store them as Log2(Alignment), so we need 5 bits to encode the 30
// 2^30. We store them as Log2(Alignment), so we need 5 bits to encode the 31
// possible values.
template <unsigned Offset>
using AlignmentBitfieldElementT =
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ class Value {
///
/// This is the greatest alignment value supported by load, store, and alloca
/// instructions, and global values.
static constexpr unsigned MaxAlignmentExponent = 29;
static constexpr unsigned MaxAlignmentExponent = 30;
static constexpr unsigned MaximumAlignment = 1u << MaxAlignmentExponent;

/// Mutate the type of this Value to be of the specified type.
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/align-inst-alloca.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: not llvm-as %s -o /dev/null 2>/dev/null

define void @foo() {
%p = alloca i1, align 1073741824
%p = alloca i1, align 2147483648
ret void
}
4 changes: 2 additions & 2 deletions llvm/test/Assembler/align-inst-load.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: not llvm-as %s -o /dev/null 2>/dev/null

define void @foo() {
load i1, i1* %p, align 1073741824
define void @foo(i1* %p) {
load i1, i1* %p, align 2147483648
ret void
}
4 changes: 2 additions & 2 deletions llvm/test/Assembler/align-inst-store.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: not llvm-as %s -o /dev/null 2>/dev/null

define void @foo() {
store i1 false, i1* %p, align 1073741824
define void @foo(i1* %p) {
store i1 false, i1* %p, align 2147483648
ret void
}
8 changes: 4 additions & 4 deletions llvm/test/Assembler/align-inst.ll
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
; RUN: llvm-as %s -o /dev/null
; RUN: verify-uselistorder %s

@A = global i1 0, align 536870912
@A = global i1 0, align 1073741824

define void @foo() {
%p = alloca i1, align 536870912
load i1, i1* %p, align 536870912
store i1 false, i1* %p, align 536870912
%p = alloca i1, align 1073741824
load i1, i1* %p, align 1073741824
store i1 false, i1* %p, align 1073741824
ret void
}
4 changes: 2 additions & 2 deletions llvm/test/Bitcode/inalloca.ll
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ define void @foo(i32* inalloca(i32) %args) {

define void @bar() {
; Use the maximum alignment, since we stuff our bit with alignment.
%args = alloca inalloca i32, align 536870912
%args = alloca inalloca i32, align 1073741824
call void @foo(i32* inalloca(i32) %args)
ret void
}
; CHECK-LABEL: define void @bar() {
; CHECK: %args = alloca inalloca i32, align 536870912
; CHECK: %args = alloca inalloca i32, align 1073741824
; CHECK: call void @foo(i32* inalloca(i32) %args)
Loading

0 comments on commit 564d85e

Please sign in to comment.