File: assume-aligned-and-alloc-align-attributes.c

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,388 kB
  • sloc: cpp: 7,438,767; ansic: 1,393,871; asm: 1,012,926; python: 241,728; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (45 lines) | stat: -rw-r--r-- 1,715 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s

void *my_aligned_alloc(int size, int alignment) __attribute__((assume_aligned(32), alloc_align(2)));

// CHECK-LABEL: @t0_immediate0(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    [[CALL:%.*]] = call align 32 ptr @my_aligned_alloc(i32 noundef 320, i32 noundef 16)
// CHECK-NEXT:    ret ptr [[CALL]]
//
void *t0_immediate0(void) {
  return my_aligned_alloc(320, 16);
};

// CHECK-LABEL: @t1_immediate1(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    [[CALL:%.*]] = call align 32 ptr @my_aligned_alloc(i32 noundef 320, i32 noundef 32)
// CHECK-NEXT:    ret ptr [[CALL]]
//
void *t1_immediate1(void) {
  return my_aligned_alloc(320, 32);
};

// CHECK-LABEL: @t2_immediate2(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    [[CALL:%.*]] = call align 64 ptr @my_aligned_alloc(i32 noundef 320, i32 noundef 64)
// CHECK-NEXT:    ret ptr [[CALL]]
//
void *t2_immediate2(void) {
  return my_aligned_alloc(320, 64);
};

// CHECK-LABEL: @t3_variable(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    [[ALIGNMENT_ADDR:%.*]] = alloca i32, align 4
// CHECK-NEXT:    store i32 [[ALIGNMENT:%.*]], ptr [[ALIGNMENT_ADDR]], align 4
// CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[ALIGNMENT_ADDR]], align 4
// CHECK-NEXT:    [[CALL:%.*]] = call align 32 ptr @my_aligned_alloc(i32 noundef 320, i32 noundef [[TMP0]])
// CHECK-NEXT:    [[CASTED_ALIGN:%.*]] = zext i32 [[TMP0]] to i64
// CHECK-NEXT:    call void @llvm.assume(i1 true) [ "align"(ptr [[CALL]], i64 [[CASTED_ALIGN]]) ]
// CHECK-NEXT:    ret ptr [[CALL]]
//
void *t3_variable(int alignment) {
  return my_aligned_alloc(320, alignment);
};