2010-08-21 12:20:22 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64 -emit-llvm -o - %s | opt -S -strip -o %t
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-GLOBAL < %t %s
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-FUNCTIONS < %t %s
|
|
|
|
|
|
|
|
struct s0 {
|
|
|
|
int x;
|
|
|
|
int y __attribute__((packed));
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK-GLOBAL: @s0_align_x = global i32 4
|
|
|
|
|
2011-05-06 05:19:14 +08:00
|
|
|
// CHECK-GLOBAL: @s0_align_y = global i32 1
|
2010-08-21 12:20:22 +08:00
|
|
|
|
|
|
|
// CHECK-GLOBAL: @s0_align = global i32 4
|
|
|
|
int s0_align_x = __alignof(((struct s0*)0)->x);
|
|
|
|
int s0_align_y = __alignof(((struct s0*)0)->y);
|
|
|
|
int s0_align = __alignof(struct s0);
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define i32 @s0_load_x
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-FUNCTIONS: [[s0_load_x:%.*]] = load i32, i32* {{.*}}, align 4
|
2010-08-21 12:20:22 +08:00
|
|
|
// CHECK-FUNCTIONS: ret i32 [[s0_load_x]]
|
|
|
|
int s0_load_x(struct s0 *a) { return a->x; }
|
|
|
|
// FIXME: This seems like it should be align 1. This is actually something which
|
|
|
|
// has changed in llvm-gcc recently, previously both x and y would be loaded
|
|
|
|
// with align 1 (in 2363.1 at least).
|
|
|
|
//
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define i32 @s0_load_y
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
// CHECK-FUNCTIONS: [[s0_load_y:%.*]] = load i32, i32* {{.*}}, align 4
|
2010-08-21 12:20:22 +08:00
|
|
|
// CHECK-FUNCTIONS: ret i32 [[s0_load_y]]
|
|
|
|
int s0_load_y(struct s0 *a) { return a->y; }
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define void @s0_copy
|
Change memcpy/memove/memset to have dest and source alignment attributes (Step 1).
Summary:
Upstream LLVM is changing the the prototypes of the @llvm.memcpy/memmove/memset
intrinsics. This change updates the Clang tests for this change.
The @llvm.memcpy/memmove/memset intrinsics currently have an explicit argument
which is required to be a constant integer. It represents the alignment of the
dest (and source), and so must be the minimum of the actual alignment of the
two.
This change removes the alignment argument in favour of placing the alignment
attribute on the source and destination pointers of the memory intrinsic call.
For example, code which used to read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 100, i32 4, i1 false)
will now read
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %dest, i8* align 4 %src, i32 100, i1 false)
At this time the source and destination alignments must be the same (Step 1).
Step 2 of the change, to be landed shortly, will relax that contraint and allow
the source and destination to have different alignments.
llvm-svn: 322964
2018-01-20 01:12:54 +08:00
|
|
|
// CHECK-FUNCTIONS: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 {{.*}}, i8* align 4 {{.*}}, i64 8, i1 false)
|
2010-08-21 12:20:22 +08:00
|
|
|
void s0_copy(struct s0 *a, struct s0 *b) { *b = *a; }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
struct s1 {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
// CHECK-GLOBAL: @s1_align_x = global i32 1
|
|
|
|
// CHECK-GLOBAL: @s1_align_y = global i32 1
|
|
|
|
// CHECK-GLOBAL: @s1_align = global i32 1
|
|
|
|
int s1_align_x = __alignof(((struct s1*)0)->x);
|
|
|
|
int s1_align_y = __alignof(((struct s1*)0)->y);
|
|
|
|
int s1_align = __alignof(struct s1);
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define i32 @s1_load_x
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-FUNCTIONS: [[s1_load_x:%.*]] = load i32, i32* {{.*}}, align 1
|
2010-08-21 12:20:22 +08:00
|
|
|
// CHECK-FUNCTIONS: ret i32 [[s1_load_x]]
|
|
|
|
int s1_load_x(struct s1 *a) { return a->x; }
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define i32 @s1_load_y
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-FUNCTIONS: [[s1_load_y:%.*]] = load i32, i32* {{.*}}, align 1
|
2010-08-21 12:20:22 +08:00
|
|
|
// CHECK-FUNCTIONS: ret i32 [[s1_load_y]]
|
|
|
|
int s1_load_y(struct s1 *a) { return a->y; }
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define void @s1_copy
|
Change memcpy/memove/memset to have dest and source alignment attributes (Step 1).
Summary:
Upstream LLVM is changing the the prototypes of the @llvm.memcpy/memmove/memset
intrinsics. This change updates the Clang tests for this change.
The @llvm.memcpy/memmove/memset intrinsics currently have an explicit argument
which is required to be a constant integer. It represents the alignment of the
dest (and source), and so must be the minimum of the actual alignment of the
two.
This change removes the alignment argument in favour of placing the alignment
attribute on the source and destination pointers of the memory intrinsic call.
For example, code which used to read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 100, i32 4, i1 false)
will now read
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %dest, i8* align 4 %src, i32 100, i1 false)
At this time the source and destination alignments must be the same (Step 1).
Step 2 of the change, to be landed shortly, will relax that contraint and allow
the source and destination to have different alignments.
llvm-svn: 322964
2018-01-20 01:12:54 +08:00
|
|
|
// CHECK-FUNCTIONS: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 8, i1 false)
|
2010-08-21 12:20:22 +08:00
|
|
|
void s1_copy(struct s1 *a, struct s1 *b) { *b = *a; }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma pack(push,2)
|
|
|
|
struct s2 {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
// CHECK-GLOBAL: @s2_align_x = global i32 2
|
|
|
|
// CHECK-GLOBAL: @s2_align_y = global i32 2
|
|
|
|
// CHECK-GLOBAL: @s2_align = global i32 2
|
|
|
|
int s2_align_x = __alignof(((struct s2*)0)->x);
|
|
|
|
int s2_align_y = __alignof(((struct s2*)0)->y);
|
|
|
|
int s2_align = __alignof(struct s2);
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define i32 @s2_load_x
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-FUNCTIONS: [[s2_load_y:%.*]] = load i32, i32* {{.*}}, align 2
|
2010-08-21 12:20:22 +08:00
|
|
|
// CHECK-FUNCTIONS: ret i32 [[s2_load_y]]
|
|
|
|
int s2_load_x(struct s2 *a) { return a->x; }
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define i32 @s2_load_y
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-FUNCTIONS: [[s2_load_y:%.*]] = load i32, i32* {{.*}}, align 2
|
2010-08-21 12:20:22 +08:00
|
|
|
// CHECK-FUNCTIONS: ret i32 [[s2_load_y]]
|
|
|
|
int s2_load_y(struct s2 *a) { return a->y; }
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define void @s2_copy
|
Change memcpy/memove/memset to have dest and source alignment attributes (Step 1).
Summary:
Upstream LLVM is changing the the prototypes of the @llvm.memcpy/memmove/memset
intrinsics. This change updates the Clang tests for this change.
The @llvm.memcpy/memmove/memset intrinsics currently have an explicit argument
which is required to be a constant integer. It represents the alignment of the
dest (and source), and so must be the minimum of the actual alignment of the
two.
This change removes the alignment argument in favour of placing the alignment
attribute on the source and destination pointers of the memory intrinsic call.
For example, code which used to read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 100, i32 4, i1 false)
will now read
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %dest, i8* align 4 %src, i32 100, i1 false)
At this time the source and destination alignments must be the same (Step 1).
Step 2 of the change, to be landed shortly, will relax that contraint and allow
the source and destination to have different alignments.
llvm-svn: 322964
2018-01-20 01:12:54 +08:00
|
|
|
// CHECK-FUNCTIONS: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 2 {{.*}}, i8* align 2 {{.*}}, i64 8, i1 false)
|
2010-08-21 12:20:22 +08:00
|
|
|
void s2_copy(struct s2 *a, struct s2 *b) { *b = *a; }
|
2011-01-20 15:57:12 +08:00
|
|
|
|
|
|
|
struct __attribute__((packed, aligned)) s3 {
|
|
|
|
short aShort;
|
|
|
|
int anInt;
|
|
|
|
};
|
2011-05-06 05:19:14 +08:00
|
|
|
// CHECK-GLOBAL: @s3_1 = global i32 1
|
2011-01-20 15:57:12 +08:00
|
|
|
int s3_1 = __alignof(((struct s3*) 0)->anInt);
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-FUNCTIONS-LABEL: define i32 @test3(
|
2011-01-20 15:57:12 +08:00
|
|
|
int test3(struct s3 *ptr) {
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-FUNCTIONS: [[PTR:%.*]] = getelementptr inbounds {{%.*}}, {{%.*}}* {{%.*}}, i32 0, i32 1
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
// CHECK-FUNCTIONS-NEXT: load i32, i32* [[PTR]], align 2
|
2011-01-20 15:57:12 +08:00
|
|
|
return ptr->anInt;
|
|
|
|
}
|