llvm-project/clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
Tyker 78de7297ab Reland [AssumeBundles] Use operand bundles to encode alignment assumptions
NOTE: There is a mailing list discussion on this: http://lists.llvm.org/pipermail/llvm-dev/2019-December/137632.html

Complemantary to the assumption outliner prototype in D71692, this patch
shows how we could simplify the code emitted for an alignemnt
assumption. The generated code is smaller, less fragile, and it makes it
easier to recognize the additional use as a "assumption use".

As mentioned in D71692 and on the mailing list, we could adopt this
scheme, and similar schemes for other patterns, without adopting the
assumption outlining.
2020-09-12 15:36:06 +02:00

46 lines
1.6 KiB
C

// 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 i8* @my_aligned_alloc(i32 320, i32 16)
// CHECK-NEXT: ret i8* [[CALL]]
//
void *t0_immediate0() {
return my_aligned_alloc(320, 16);
};
// CHECK-LABEL: @t1_immediate1(
// CHECK-NEXT: entry:
// CHECK-NEXT: [[CALL:%.*]] = call align 32 i8* @my_aligned_alloc(i32 320, i32 32)
// CHECK-NEXT: ret i8* [[CALL]]
//
void *t1_immediate1() {
return my_aligned_alloc(320, 32);
};
// CHECK-LABEL: @t2_immediate2(
// CHECK-NEXT: entry:
// CHECK-NEXT: [[CALL:%.*]] = call align 64 i8* @my_aligned_alloc(i32 320, i32 64)
// CHECK-NEXT: ret i8* [[CALL]]
//
void *t2_immediate2() {
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:%.*]], i32* [[ALIGNMENT_ADDR]], align 4
// CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[ALIGNMENT_ADDR]], align 4
// CHECK-NEXT: [[CALL:%.*]] = call align 32 i8* @my_aligned_alloc(i32 320, i32 [[TMP0]])
// CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* [[CALL]], i64 [[TMP1]]) ]
// CHECK-NEXT: ret i8* [[CALL]]
//
void *t3_variable(int alignment) {
return my_aligned_alloc(320, alignment);
};