2014-09-08 06:58:14 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
|
|
|
|
|
|
|
|
// CHECK-LABEL: @test1
|
|
|
|
int test1(int *a) {
|
2014-09-08 09:12:55 +08:00
|
|
|
// CHECK: [[PTRINT1:%.+]] = ptrtoint
|
|
|
|
// CHECK: [[MASKEDPTR1:%.+]] = and i64 [[PTRINT1]], 31
|
|
|
|
// CHECK: [[MASKCOND1:%.+]] = icmp eq i64 [[MASKEDPTR1]], 0
|
|
|
|
// CHECK: call void @llvm.assume(i1 [[MASKCOND1]])
|
2014-09-08 06:58:14 +08:00
|
|
|
a = __builtin_assume_aligned(a, 32, 0ull);
|
|
|
|
return a[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @test2
|
|
|
|
int test2(int *a) {
|
2014-09-08 09:12:55 +08:00
|
|
|
// CHECK: [[PTRINT2:%.+]] = ptrtoint
|
|
|
|
// CHECK: [[MASKEDPTR2:%.+]] = and i64 [[PTRINT2]], 31
|
|
|
|
// CHECK: [[MASKCOND2:%.+]] = icmp eq i64 [[MASKEDPTR2]], 0
|
|
|
|
// CHECK: call void @llvm.assume(i1 [[MASKCOND2]])
|
2014-09-08 06:58:14 +08:00
|
|
|
a = __builtin_assume_aligned(a, 32, 0);
|
|
|
|
return a[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @test3
|
|
|
|
int test3(int *a) {
|
2014-09-08 09:12:55 +08:00
|
|
|
// CHECK: [[PTRINT3:%.+]] = ptrtoint
|
|
|
|
// CHECK: [[MASKEDPTR3:%.+]] = and i64 [[PTRINT3]], 31
|
|
|
|
// CHECK: [[MASKCOND3:%.+]] = icmp eq i64 [[MASKEDPTR3]], 0
|
|
|
|
// CHECK: call void @llvm.assume(i1 [[MASKCOND3]])
|
2014-09-08 06:58:14 +08:00
|
|
|
a = __builtin_assume_aligned(a, 32);
|
|
|
|
return a[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @test4
|
|
|
|
int test4(int *a, int b) {
|
2014-09-08 09:12:55 +08:00
|
|
|
// CHECK-DAG: [[PTRINT4:%.+]] = ptrtoint
|
|
|
|
// CHECK-DAG: [[CONV4:%.+]] = sext i32
|
|
|
|
// CHECK: [[OFFSETPTR4:%.+]] = sub i64 [[PTRINT4]], [[CONV4]]
|
|
|
|
// CHECK: [[MASKEDPTR4:%.+]] = and i64 [[OFFSETPTR4]], 31
|
|
|
|
// CHECK: [[MASKCOND4:%.+]] = icmp eq i64 [[MASKEDPTR4]], 0
|
|
|
|
// CHECK: call void @llvm.assume(i1 [[MASKCOND4]])
|
2014-09-08 06:58:14 +08:00
|
|
|
a = __builtin_assume_aligned(a, 32, b);
|
|
|
|
return a[0];
|
|
|
|
}
|
|
|
|
|
2014-09-26 13:04:30 +08:00
|
|
|
int *m1() __attribute__((assume_aligned(64)));
|
|
|
|
|
[Codegen] If reasonable, materialize clang's `AssumeAlignedAttr` as llvm's Alignment Attribute on call-site function return value
Summary:
This should be mostly NFC - we still lower the same alignment
knowledge to the IR. The main reasoning here is that
this somewhat improves readability of IR like this,
and will improve test coverage in upcoming patch.
Even though the alignment is guaranteed to always be an I-C-E,
we don't always materialize it as llvm's Alignment Attribute because:
1. There may be a non-zero offset
2. We may be sanitizing for alignment
Note that if there already was an IR alignment attribute
on return value, we union them, and thus the alignment
only ever rises.
Also, there is a second relevant clang attribute `AllocAlignAttr`,
so that is why `AbstractAssumeAlignedAttrEmitter` is templated.
Reviewers: erichkeane, jdoerfert, hfinkel, aaron.ballman, rsmith
Reviewed By: erichkeane
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73005
2020-01-24 03:50:15 +08:00
|
|
|
// CHECK-LABEL: @test5(
|
|
|
|
// CHECK-NEXT: entry:
|
|
|
|
// CHECK-NEXT: [[CALL:%.*]] = call align 64 i32* (...) @m1()
|
|
|
|
// CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[CALL]], align 4
|
|
|
|
// CHECK-NEXT: ret i32 [[TMP0]]
|
|
|
|
//
|
2014-09-26 13:04:30 +08:00
|
|
|
int test5() {
|
|
|
|
return *m1();
|
|
|
|
}
|
|
|
|
|
|
|
|
int *m2() __attribute__((assume_aligned(64, 12)));
|
|
|
|
|
|
|
|
// CHECK-LABEL: @test6
|
|
|
|
int test6() {
|
|
|
|
return *m2();
|
2014-09-26 17:37:15 +08:00
|
|
|
// CHECK: [[PTRINT6:%.+]] = ptrtoint
|
|
|
|
// CHECK: [[OFFSETPTR6:%.+]] = sub i64 [[PTRINT6]], 12
|
|
|
|
// CHECK: [[MASKEDPTR6:%.+]] = and i64 [[OFFSETPTR6]], 63
|
|
|
|
// CHECK: [[MASKCOND6:%.+]] = icmp eq i64 [[MASKEDPTR6]], 0
|
|
|
|
// CHECK: call void @llvm.assume(i1 [[MASKCOND6]])
|
2014-09-26 13:04:30 +08:00
|
|
|
}
|
|
|
|
|
2019-10-11 22:59:44 +08:00
|
|
|
// CHECK-LABEL: @pr43638
|
|
|
|
int pr43638(int *a) {
|
|
|
|
a = __builtin_assume_aligned(a, 4294967296);
|
|
|
|
return a[0];
|
|
|
|
// CHECK: [[PTRINT7:%.+]] = ptrtoint
|
|
|
|
// CHECK: [[MASKEDPTR7:%.+]] = and i64 [[PTRINT7]], 536870911
|
|
|
|
// CHECK: [[MASKCOND7:%.+]] = icmp eq i64 [[MASKEDPTR7]], 0
|
|
|
|
// CHECK: call void @llvm.assume(i1 [[MASKCOND7]])
|
|
|
|
}
|