2014-01-28 01:56:25 +08:00
|
|
|
// REQUIRES: xcore-registered-target
|
2013-11-12 18:09:34 +08:00
|
|
|
// RUN: %clang_cc1 -triple xcore -verify %s
|
|
|
|
_Static_assert(sizeof(long long) == 8, "sizeof long long is wrong");
|
|
|
|
_Static_assert(_Alignof(long long) == 4, "alignof long long is wrong");
|
|
|
|
|
|
|
|
_Static_assert(sizeof(double) == 8, "sizeof double is wrong");
|
|
|
|
_Static_assert(_Alignof(double) == 4, "alignof double is wrong");
|
|
|
|
|
2013-08-23 17:27:44 +08:00
|
|
|
// RUN: %clang_cc1 -triple xcore-unknown-unknown -fno-signed-char -fno-common -emit-llvm -o - %s | FileCheck %s
|
2013-08-13 17:43:10 +08:00
|
|
|
|
2013-08-23 17:27:44 +08:00
|
|
|
// CHECK: target triple = "xcore-unknown-unknown"
|
2013-08-13 17:43:10 +08:00
|
|
|
|
2014-02-11 18:34:51 +08:00
|
|
|
// CHECK: @cgx = external constant i32, section ".cp.rodata"
|
|
|
|
extern const int cgx;
|
|
|
|
int fcgx() { return cgx;}
|
2013-08-19 17:46:32 +08:00
|
|
|
// CHECK: @g1 = global i32 0, align 4
|
|
|
|
int g1;
|
2014-02-11 18:34:51 +08:00
|
|
|
// CHECK: @cg1 = constant i32 0, section ".cp.rodata", align 4
|
|
|
|
const int cg1;
|
2013-08-19 17:46:32 +08:00
|
|
|
|
2013-08-13 17:43:10 +08:00
|
|
|
#include <stdarg.h>
|
2013-08-19 17:46:39 +08:00
|
|
|
struct x { int a[5]; };
|
|
|
|
void f(void*);
|
2013-08-13 17:43:10 +08:00
|
|
|
void testva (int n, ...) {
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK-LABEL: testva
|
2013-08-13 17:43:10 +08:00
|
|
|
va_list ap;
|
2013-08-19 17:46:39 +08:00
|
|
|
va_start(ap,n);
|
2013-08-13 22:51:38 +08:00
|
|
|
// CHECK: [[AP:%[a-z0-9]+]] = alloca i8*, align 4
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: [[AP1:%[a-z0-9]+]] = bitcast i8** [[AP]] to i8*
|
|
|
|
// CHECK: call void @llvm.va_start(i8* [[AP1]])
|
2013-08-13 17:43:10 +08:00
|
|
|
|
|
|
|
char* v1 = va_arg (ap, char*);
|
2013-08-19 17:46:39 +08:00
|
|
|
f(v1);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
|
2013-10-11 18:29:34 +08:00
|
|
|
// CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to i8**
|
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: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 4
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: store i8* [[IN]], i8** [[AP]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[V1:%[a-z0-9]+]] = load i8*, i8** [[P]]
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: store i8* [[V1]], i8** [[V:%[a-z0-9]+]], align 4
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[V2:%[a-z0-9]+]] = load i8*, i8** [[V]], align 4
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: call void @f(i8* [[V2]])
|
2013-08-13 17:43:10 +08:00
|
|
|
|
2013-11-12 18:09:34 +08:00
|
|
|
char v2 = va_arg (ap, char); // expected-warning{{second argument to 'va_arg' is of promotable type 'char'}}
|
2013-08-19 17:46:39 +08:00
|
|
|
f(&v2);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
|
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: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 4
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: store i8* [[IN]], i8** [[AP]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[V1:%[a-z0-9]+]] = load i8, i8* [[I]]
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: store i8 [[V1]], i8* [[V:%[a-z0-9]+]], align 1
|
|
|
|
// CHECK: call void @f(i8* [[V]])
|
2013-08-13 17:43:10 +08:00
|
|
|
|
2013-08-19 17:46:39 +08:00
|
|
|
int v3 = va_arg (ap, int);
|
|
|
|
f(&v3);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
|
2013-10-11 18:29:34 +08:00
|
|
|
// CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to i32*
|
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: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 4
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: store i8* [[IN]], i8** [[AP]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[V1:%[a-z0-9]+]] = load i32, i32* [[P]]
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: store i32 [[V1]], i32* [[V:%[a-z0-9]+]], align 4
|
|
|
|
// CHECK: [[V2:%[a-z0-9]+]] = bitcast i32* [[V]] to i8*
|
|
|
|
// CHECK: call void @f(i8* [[V2]])
|
2013-08-13 17:43:10 +08:00
|
|
|
|
2013-08-19 17:46:39 +08:00
|
|
|
long long int v4 = va_arg (ap, long long int);
|
|
|
|
f(&v4);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to i64*
|
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: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 8
|
2013-10-11 18:29:34 +08:00
|
|
|
// CHECK: store i8* [[IN]], i8** [[AP]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[V1:%[a-z0-9]+]] = load i64, i64* [[P]]
|
2013-11-12 18:09:34 +08:00
|
|
|
// CHECK: store i64 [[V1]], i64* [[V:%[a-z0-9]+]], align 4
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK:[[V2:%[a-z0-9]+]] = bitcast i64* [[V]] to i8*
|
|
|
|
// CHECK: call void @f(i8* [[V2]])
|
|
|
|
|
2013-12-06 00:25:25 +08:00
|
|
|
struct x v5 = va_arg (ap, struct x); // typical aggregate type
|
2013-08-19 17:46:39 +08:00
|
|
|
f(&v5);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: [[I2:%[a-z0-9]+]] = bitcast i8* [[I]] to %struct.x**
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[P:%[a-z0-9]+]] = load %struct.x*, %struct.x** [[I2]]
|
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: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 4
|
2013-10-11 18:29:34 +08:00
|
|
|
// CHECK: store i8* [[IN]], i8** [[AP]]
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: [[V1:%[a-z0-9]+]] = bitcast %struct.x* [[V:%[a-z0-9]+]] to i8*
|
|
|
|
// CHECK: [[P1:%[a-z0-9]+]] = bitcast %struct.x* [[P]] to i8*
|
|
|
|
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[V1]], i8* [[P1]], i32 20, i32 4, i1 false)
|
|
|
|
// CHECK: [[V2:%[a-z0-9]+]] = bitcast %struct.x* [[V]] to i8*
|
|
|
|
// CHECK: call void @f(i8* [[V2]])
|
|
|
|
|
2013-12-06 00:25:25 +08:00
|
|
|
int* v6 = va_arg (ap, int[4]); // an unusual aggregate type
|
2013-08-19 17:46:39 +08:00
|
|
|
f(v6);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: [[I2:%[a-z0-9]+]] = bitcast i8* [[I]] to [4 x i32]**
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[P:%[a-z0-9]+]] = load [4 x i32]*, [4 x i32]** [[I2]]
|
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: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 4
|
2013-10-11 18:29:34 +08:00
|
|
|
// CHECK: store i8* [[IN]], i8** [[AP]]
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: [[V1:%[a-z0-9]+]] = bitcast [4 x i32]* [[V0:%[a-z0-9]+]] to i8*
|
|
|
|
// CHECK: [[P1:%[a-z0-9]+]] = bitcast [4 x i32]* [[P]] to i8*
|
|
|
|
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[V1]], i8* [[P1]], i32 16, i32 4, i1 false)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[V2:%[a-z0-9]+]] = getelementptr inbounds [4 x i32], [4 x i32]* [[V0]], i32 0, i32 0
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: store i32* [[V2]], i32** [[V:%[a-z0-9]+]], align 4
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[V3:%[a-z0-9]+]] = load i32*, i32** [[V]], align 4
|
2013-08-19 17:46:39 +08:00
|
|
|
// CHECK: [[V4:%[a-z0-9]+]] = bitcast i32* [[V3]] to i8*
|
|
|
|
// CHECK: call void @f(i8* [[V4]])
|
2013-10-11 18:29:34 +08:00
|
|
|
|
|
|
|
double v7 = va_arg (ap, double);
|
|
|
|
f(&v7);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[I:%[a-z0-9]+]] = load i8*, i8** [[AP]]
|
2013-10-11 18:29:34 +08:00
|
|
|
// CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to double*
|
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: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, i8* [[I]], i32 8
|
2013-10-11 18:29:34 +08:00
|
|
|
// CHECK: store i8* [[IN]], i8** [[AP]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[V1:%[a-z0-9]+]] = load double, double* [[P]]
|
2013-11-12 18:09:34 +08:00
|
|
|
// CHECK: store double [[V1]], double* [[V:%[a-z0-9]+]], align 4
|
2013-10-11 18:29:34 +08:00
|
|
|
// CHECK: [[V2:%[a-z0-9]+]] = bitcast double* [[V]] to i8*
|
|
|
|
// CHECK: call void @f(i8* [[V2]])
|
2013-08-13 17:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void testbuiltin (void) {
|
2013-08-19 17:46:32 +08:00
|
|
|
// CHECK-LABEL: testbuiltin
|
|
|
|
// CHECK: call i32 @llvm.xcore.getid()
|
|
|
|
// CHECK: call i32 @llvm.xcore.getps(i32 {{%[a-z0-9]+}})
|
|
|
|
// CHECK: call i32 @llvm.xcore.bitrev(i32 {{%[a-z0-9]+}})
|
|
|
|
// CHECK: call void @llvm.xcore.setps(i32 {{%[a-z0-9]+}}, i32 {{%[a-z0-9]+}})
|
2014-01-28 01:56:25 +08:00
|
|
|
volatile int i = __builtin_getid();
|
|
|
|
volatile unsigned int ui = __builtin_getps(i);
|
2013-08-13 17:43:10 +08:00
|
|
|
ui = __builtin_bitrev(ui);
|
|
|
|
__builtin_setps(i,ui);
|
2014-01-28 01:56:25 +08:00
|
|
|
|
|
|
|
// CHECK: store volatile i32 0, i32* {{%[a-z0-9]+}}, align 4
|
|
|
|
// CHECK: store volatile i32 1, i32* {{%[a-z0-9]+}}, align 4
|
|
|
|
// CHECK: store volatile i32 -1, i32* {{%[a-z0-9]+}}, align 4
|
|
|
|
volatile int res;
|
|
|
|
res = __builtin_eh_return_data_regno(0);
|
|
|
|
res = __builtin_eh_return_data_regno(1);
|
|
|
|
res = __builtin_eh_return_data_regno(2);
|
2013-08-19 17:46:32 +08:00
|
|
|
}
|
2013-08-13 17:43:10 +08:00
|
|
|
|
2013-08-19 17:46:32 +08:00
|
|
|
// CHECK-LABEL: define zeroext i8 @testchar()
|
|
|
|
// CHECK: ret i8 -1
|
|
|
|
char testchar (void) {
|
|
|
|
return (char)-1;
|
2013-08-13 17:43:10 +08:00
|
|
|
}
|
2013-08-19 17:46:32 +08:00
|
|
|
|
|
|
|
// CHECK: "no-frame-pointer-elim"="false"
|
2013-08-23 05:30:21 +08:00
|
|
|
// CHECK-NOT: "no-frame-pointer-elim-non-leaf"
|