2014-08-06 02:37:48 +08:00
|
|
|
// RUN: %clang_cc1 -x c++ %s -O0 -triple=x86_64-apple-darwin -target-feature +avx2 -fmax-type-align=16 -emit-llvm -o - -Werror | FileCheck %s
|
|
|
|
// rdar://16254558
|
|
|
|
|
|
|
|
typedef float AVX2Float __attribute__((__vector_size__(32)));
|
|
|
|
|
|
|
|
|
|
|
|
volatile float TestAlign(void)
|
|
|
|
{
|
|
|
|
volatile AVX2Float *p = new AVX2Float;
|
|
|
|
*p = *p;
|
|
|
|
AVX2Float r = *p;
|
|
|
|
return r[0];
|
|
|
|
}
|
|
|
|
|
2018-06-05 05:39:20 +08:00
|
|
|
// CHECK: [[R:%.*]] = alloca <8 x float>, align 32
|
[clang] Annotating C++'s `operator new` with more attributes
Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.
However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.
Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.
The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.
Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith
Reviewed By: rsmith
Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D73380
2020-02-26 06:37:17 +08:00
|
|
|
// CHECK-NEXT: [[CALL:%.*]] = call noalias nonnull i8* @_Znwm(i64 32)
|
2014-08-06 02:37:48 +08:00
|
|
|
// CHECK-NEXT: [[ZERO:%.*]] = bitcast i8* [[CALL]] to <8 x float>*
|
|
|
|
// CHECK-NEXT: store <8 x float>* [[ZERO]], <8 x float>** [[P:%.*]], align 8
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[ONE:%.*]] = load <8 x float>*, <8 x float>** [[P]], align 8
|
|
|
|
// CHECK-NEXT: [[TWO:%.*]] = load volatile <8 x float>, <8 x float>* [[ONE]], align 16
|
|
|
|
// CHECK-NEXT: [[THREE:%.*]] = load <8 x float>*, <8 x float>** [[P]], align 8
|
2014-08-06 02:37:48 +08:00
|
|
|
// CHECK-NEXT: store volatile <8 x float> [[TWO]], <8 x float>* [[THREE]], align 16
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[FOUR:%.*]] = load <8 x float>*, <8 x float>** [[P]], align 8
|
|
|
|
// CHECK-NEXT: [[FIVE:%.*]] = load volatile <8 x float>, <8 x float>* [[FOUR]], align 16
|
2018-06-05 05:39:20 +08:00
|
|
|
// CHECK-NEXT: store <8 x float> [[FIVE]], <8 x float>* [[R]], align 32
|
|
|
|
// CHECK-NEXT: [[SIX:%.*]] = load <8 x float>, <8 x float>* [[R]], align 32
|
2014-08-06 02:37:48 +08:00
|
|
|
// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <8 x float> [[SIX]], i32 0
|
|
|
|
// CHECK-NEXT: ret float [[VECEXT]]
|
|
|
|
|
|
|
|
typedef float AVX2Float_Explicitly_aligned __attribute__((__vector_size__(32))) __attribute__((aligned (32)));
|
|
|
|
|
|
|
|
typedef AVX2Float_Explicitly_aligned AVX2Float_indirect;
|
|
|
|
|
|
|
|
typedef AVX2Float_indirect AVX2Float_use_existing_align;
|
|
|
|
|
|
|
|
volatile float TestAlign2(void)
|
|
|
|
{
|
|
|
|
volatile AVX2Float_use_existing_align *p = new AVX2Float_use_existing_align;
|
|
|
|
*p = *p;
|
|
|
|
AVX2Float_use_existing_align r = *p;
|
|
|
|
return r[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: [[R:%.*]] = alloca <8 x float>, align 32
|
[clang] Annotating C++'s `operator new` with more attributes
Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.
However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.
Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.
The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.
Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith
Reviewed By: rsmith
Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D73380
2020-02-26 06:37:17 +08:00
|
|
|
// CHECK-NEXT: [[CALL:%.*]] = call noalias nonnull i8* @_Znwm(i64 32)
|
2014-08-06 02:37:48 +08:00
|
|
|
// CHECK-NEXT: [[ZERO:%.*]] = bitcast i8* [[CALL]] to <8 x float>*
|
|
|
|
// CHECK-NEXT: store <8 x float>* [[ZERO]], <8 x float>** [[P:%.*]], align 8
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[ONE:%.*]] = load <8 x float>*, <8 x float>** [[P]], align 8
|
|
|
|
// CHECK-NEXT: [[TWO:%.*]] = load volatile <8 x float>, <8 x float>* [[ONE]], align 32
|
|
|
|
// CHECK-NEXT: [[THREE:%.*]] = load <8 x float>*, <8 x float>** [[P]], align 8
|
2014-08-06 02:37:48 +08:00
|
|
|
// CHECK-NEXT: store volatile <8 x float> [[TWO]], <8 x float>* [[THREE]], align 32
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[FOUR:%.*]] = load <8 x float>*, <8 x float>** [[P]], align 8
|
|
|
|
// CHECK-NEXT: [[FIVE:%.*]] = load volatile <8 x float>, <8 x float>* [[FOUR]], align 32
|
2014-08-06 02:37:48 +08:00
|
|
|
// CHECK-NEXT: store <8 x float> [[FIVE]], <8 x float>* [[R]], align 32
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[SIX:%.*]] = load <8 x float>, <8 x float>* [[R]], align 32
|
2014-08-06 02:37:48 +08:00
|
|
|
// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <8 x float> [[SIX]], i32 0
|
|
|
|
// CHECK-NEXT: ret float [[VECEXT]]
|