| 1 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s |
| 2 | // RUN: %clang_cc1 -triple i386-mingw32 -fms-extensions -emit-llvm -o - %s | FileCheck %s |
| 3 | |
| 4 | int nonconst(void); |
| 5 | int isconst(void) __attribute__((const)); |
| 6 | int ispure(void) __attribute__((pure)); |
| 7 | |
| 8 | // CHECK-LABEL: @test1 |
| 9 | int test1(int *a, int i) { |
| 10 | // CHECK: store i32* %a, i32** [[A_ADDR:%.+]], align |
| 11 | // CHECK: [[A:%.+]] = load i32*, i32** [[A_ADDR]] |
| 12 | // CHECK: [[CMP:%.+]] = icmp ne i32* [[A]], null |
| 13 | // CHECK: call void @llvm.assume(i1 [[CMP]]) |
| 14 | |
| 15 | // CHECK: [[CALL:%.+]] = call i32 @isconst() |
| 16 | // CHECK: [[BOOL:%.+]] = icmp ne i32 [[CALL]], 0 |
| 17 | // CHECK: call void @llvm.assume(i1 [[BOOL]]) |
| 18 | |
| 19 | // CHECK: [[CALLPURE:%.+]] = call i32 @ispure() |
| 20 | // CHECK: [[BOOLPURE:%.+]] = icmp ne i32 [[CALLPURE]], 0 |
| 21 | // CHECK: call void @llvm.assume(i1 [[BOOLPURE]]) |
| 22 | #ifdef _MSC_VER |
| 23 | __assume(a != 0) |
| 24 | __assume(isconst()); |
| 25 | __assume(ispure()); |
| 26 | #else |
| 27 | __builtin_assume(a != 0); |
| 28 | __builtin_assume(isconst()); |
| 29 | __builtin_assume(ispure()); |
| 30 | #endif |
| 31 | |
| 32 | // Nothing is generated for an assume with side effects... |
| 33 | // CHECK-NOT: load i32*, i32** %i.addr |
| 34 | // CHECK-NOT: call void @llvm.assume |
| 35 | // CHECK-NOT: call i32 @nonconst() |
| 36 | #ifdef _MSC_VER |
| 37 | __assume(++i != 0) |
| 38 | __assume(nonconst()); |
| 39 | #else |
| 40 | __builtin_assume(++i != 0); |
| 41 | __builtin_assume(nonconst()); |
| 42 | #endif |
| 43 | |
| 44 | return a[0]; |
| 45 | } |
| 46 | |
| 47 | |