Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s |
Hal Finkel | 3e49fda | 2014-07-16 22:44:54 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -triple i386-mingw32 -fms-extensions -emit-llvm -o - %s | FileCheck %s |
| 3 | |
Michael Kuperstein | aed5ccd | 2015-04-06 13:22:01 +0000 | [diff] [blame^] | 4 | int nonconst(void); |
| 5 | int isconst(void) __attribute__((const)); |
| 6 | int ispure(void) __attribute__((pure)); |
| 7 | |
Hal Finkel | 3e49fda | 2014-07-16 22:44:54 +0000 | [diff] [blame] | 8 | // CHECK-LABEL: @test1 |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 9 | int test1(int *a, int i) { |
NAKAMURA Takumi | 4b04c11 | 2014-09-08 01:12:55 +0000 | [diff] [blame] | 10 | // CHECK: store i32* %a, i32** [[A_ADDR:%.+]], align |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 11 | // CHECK: [[A:%.+]] = load i32*, i32** [[A_ADDR]] |
NAKAMURA Takumi | 4b04c11 | 2014-09-08 01:12:55 +0000 | [diff] [blame] | 12 | // CHECK: [[CMP:%.+]] = icmp ne i32* [[A]], null |
| 13 | // CHECK: call void @llvm.assume(i1 [[CMP]]) |
Michael Kuperstein | aed5ccd | 2015-04-06 13:22:01 +0000 | [diff] [blame^] | 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]]) |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 22 | #ifdef _MSC_VER |
| 23 | __assume(a != 0) |
Michael Kuperstein | aed5ccd | 2015-04-06 13:22:01 +0000 | [diff] [blame^] | 24 | __assume(isconst()); |
| 25 | __assume(ispure()); |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 26 | #else |
| 27 | __builtin_assume(a != 0); |
Michael Kuperstein | aed5ccd | 2015-04-06 13:22:01 +0000 | [diff] [blame^] | 28 | __builtin_assume(isconst()); |
| 29 | __builtin_assume(ispure()); |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 30 | #endif |
| 31 | |
| 32 | // Nothing is generated for an assume with side effects... |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 33 | // CHECK-NOT: load i32*, i32** %i.addr |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 34 | // CHECK-NOT: call void @llvm.assume |
Michael Kuperstein | aed5ccd | 2015-04-06 13:22:01 +0000 | [diff] [blame^] | 35 | // CHECK-NOT: call i32 @nonconst() |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 36 | #ifdef _MSC_VER |
| 37 | __assume(++i != 0) |
Michael Kuperstein | aed5ccd | 2015-04-06 13:22:01 +0000 | [diff] [blame^] | 38 | __assume(nonconst()); |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 39 | #else |
| 40 | __builtin_assume(++i != 0); |
Michael Kuperstein | aed5ccd | 2015-04-06 13:22:01 +0000 | [diff] [blame^] | 41 | __builtin_assume(nonconst()); |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
Hal Finkel | 3e49fda | 2014-07-16 22:44:54 +0000 | [diff] [blame] | 44 | return a[0]; |
| 45 | } |
| 46 | |