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