1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @test1
test1(int * a)4*0a6a1f1dSLionel Sambuc int test1(int *a) {
5*0a6a1f1dSLionel Sambuc // CHECK: [[PTRINT1:%.+]] = ptrtoint
6*0a6a1f1dSLionel Sambuc // CHECK: [[MASKEDPTR1:%.+]] = and i64 [[PTRINT1]], 31
7*0a6a1f1dSLionel Sambuc // CHECK: [[MASKCOND1:%.+]] = icmp eq i64 [[MASKEDPTR1]], 0
8*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.assume(i1 [[MASKCOND1]])
9*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 32, 0ull);
10*0a6a1f1dSLionel Sambuc return a[0];
11*0a6a1f1dSLionel Sambuc }
12*0a6a1f1dSLionel Sambuc
13*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @test2
test2(int * a)14*0a6a1f1dSLionel Sambuc int test2(int *a) {
15*0a6a1f1dSLionel Sambuc // CHECK: [[PTRINT2:%.+]] = ptrtoint
16*0a6a1f1dSLionel Sambuc // CHECK: [[MASKEDPTR2:%.+]] = and i64 [[PTRINT2]], 31
17*0a6a1f1dSLionel Sambuc // CHECK: [[MASKCOND2:%.+]] = icmp eq i64 [[MASKEDPTR2]], 0
18*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.assume(i1 [[MASKCOND2]])
19*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 32, 0);
20*0a6a1f1dSLionel Sambuc return a[0];
21*0a6a1f1dSLionel Sambuc }
22*0a6a1f1dSLionel Sambuc
23*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @test3
test3(int * a)24*0a6a1f1dSLionel Sambuc int test3(int *a) {
25*0a6a1f1dSLionel Sambuc // CHECK: [[PTRINT3:%.+]] = ptrtoint
26*0a6a1f1dSLionel Sambuc // CHECK: [[MASKEDPTR3:%.+]] = and i64 [[PTRINT3]], 31
27*0a6a1f1dSLionel Sambuc // CHECK: [[MASKCOND3:%.+]] = icmp eq i64 [[MASKEDPTR3]], 0
28*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.assume(i1 [[MASKCOND3]])
29*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 32);
30*0a6a1f1dSLionel Sambuc return a[0];
31*0a6a1f1dSLionel Sambuc }
32*0a6a1f1dSLionel Sambuc
33*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @test4
test4(int * a,int b)34*0a6a1f1dSLionel Sambuc int test4(int *a, int b) {
35*0a6a1f1dSLionel Sambuc // CHECK-DAG: [[PTRINT4:%.+]] = ptrtoint
36*0a6a1f1dSLionel Sambuc // CHECK-DAG: [[CONV4:%.+]] = sext i32
37*0a6a1f1dSLionel Sambuc // CHECK: [[OFFSETPTR4:%.+]] = sub i64 [[PTRINT4]], [[CONV4]]
38*0a6a1f1dSLionel Sambuc // CHECK: [[MASKEDPTR4:%.+]] = and i64 [[OFFSETPTR4]], 31
39*0a6a1f1dSLionel Sambuc // CHECK: [[MASKCOND4:%.+]] = icmp eq i64 [[MASKEDPTR4]], 0
40*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.assume(i1 [[MASKCOND4]])
41*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 32, b);
42*0a6a1f1dSLionel Sambuc return a[0];
43*0a6a1f1dSLionel Sambuc }
44*0a6a1f1dSLionel Sambuc
45*0a6a1f1dSLionel Sambuc int *m1() __attribute__((assume_aligned(64)));
46*0a6a1f1dSLionel Sambuc
47*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @test5
test5()48*0a6a1f1dSLionel Sambuc int test5() {
49*0a6a1f1dSLionel Sambuc return *m1();
50*0a6a1f1dSLionel Sambuc // CHECK: [[PTRINT5:%.+]] = ptrtoint
51*0a6a1f1dSLionel Sambuc // CHECK: [[MASKEDPTR5:%.+]] = and i64 [[PTRINT5]], 63
52*0a6a1f1dSLionel Sambuc // CHECK: [[MASKCOND5:%.+]] = icmp eq i64 [[MASKEDPTR5]], 0
53*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.assume(i1 [[MASKCOND5]])
54*0a6a1f1dSLionel Sambuc }
55*0a6a1f1dSLionel Sambuc
56*0a6a1f1dSLionel Sambuc int *m2() __attribute__((assume_aligned(64, 12)));
57*0a6a1f1dSLionel Sambuc
58*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @test6
test6()59*0a6a1f1dSLionel Sambuc int test6() {
60*0a6a1f1dSLionel Sambuc return *m2();
61*0a6a1f1dSLionel Sambuc // CHECK: [[PTRINT6:%.+]] = ptrtoint
62*0a6a1f1dSLionel Sambuc // CHECK: [[OFFSETPTR6:%.+]] = sub i64 [[PTRINT6]], 12
63*0a6a1f1dSLionel Sambuc // CHECK: [[MASKEDPTR6:%.+]] = and i64 [[OFFSETPTR6]], 63
64*0a6a1f1dSLionel Sambuc // CHECK: [[MASKCOND6:%.+]] = icmp eq i64 [[MASKEDPTR6]], 0
65*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.assume(i1 [[MASKCOND6]])
66*0a6a1f1dSLionel Sambuc }
67*0a6a1f1dSLionel Sambuc
68