1 // RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -o - -triple arm64-none-linux-gnu | FileCheck %s
2 
3 // Test that the constrained intrinsics are picking up the exception
4 // metadata from the AST instead of the global default from the command line.
5 
6 #pragma float_control(except, on)
7 
8 int printf(const char *, ...);
9 
10 // CHECK-LABEL: @p(
11 // CHECK-NEXT:  entry:
12 // CHECK-NEXT:    [[STR_ADDR:%.*]] = alloca i8*, align 8
13 // CHECK-NEXT:    [[X_ADDR:%.*]] = alloca i32, align 4
14 // CHECK-NEXT:    store i8* [[STR:%.*]], i8** [[STR_ADDR]], align 8
15 // CHECK-NEXT:    store i32 [[X:%.*]], i32* [[X_ADDR]], align 4
16 // CHECK-NEXT:    [[TMP0:%.*]] = load i8*, i8** [[STR_ADDR]], align 8
17 // CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[X_ADDR]], align 4
18 // CHECK-NEXT:    [[CALL:%.*]] = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* [[TMP0]], i32 [[TMP1]])  [[ATTR4:#.*]]
19 // CHECK-NEXT:    ret void
20 //
p(char * str,int x)21 void p(char *str, int x) {
22   printf("%s: %d\n", str, x);
23 }
24 
25 #define P(n,args) p(#n #args, __builtin_##n args)
26 
27 // CHECK-LABEL: @test_long_double_isinf(
28 // CHECK-NEXT:  entry:
29 // CHECK-NEXT:    [[LD_ADDR:%.*]] = alloca fp128, align 16
30 // CHECK-NEXT:    store fp128 [[D:%.*]], fp128* [[LD_ADDR]], align 16
31 // CHECK-NEXT:    [[TMP0:%.*]] = load fp128, fp128* [[LD_ADDR]], align 16
32 // CHECK-NEXT:    [[BITCAST:%.*]] = bitcast fp128 [[TMP0]] to i128
33 // CHECK-NEXT:    [[SHL1:%.*]] = shl i128 [[BITCAST]], 1
34 // CHECK-NEXT:    [[CMP:%.*]] = icmp eq i128 [[SHL1]], -10384593717069655257060992658440192
35 // CHECK-NEXT:    [[RES:%.*]] = zext i1 [[CMP]] to i32
36 // CHECK-NEXT:    call void @p(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.[[#STRID:1]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
37 // CHECK-NEXT:    ret void
38 //
test_long_double_isinf(long double ld)39 void test_long_double_isinf(long double ld) {
40   P(isinf, (ld));
41 
42   return;
43 }
44 
45 // CHECK-LABEL: @test_long_double_isfinite(
46 // CHECK-NEXT:  entry:
47 // CHECK-NEXT:    [[LD_ADDR:%.*]] = alloca fp128, align 16
48 // CHECK-NEXT:    store fp128 [[D:%.*]], fp128* [[LD_ADDR]], align 16
49 // CHECK-NEXT:    [[TMP0:%.*]] = load fp128, fp128* [[LD_ADDR]], align 16
50 // CHECK-NEXT:    [[BITCAST:%.*]] = bitcast fp128 [[TMP0]] to i128
51 // CHECK-NEXT:    [[SHL1:%.*]] = shl i128 [[BITCAST]], 1
52 // CHECK-NEXT:    [[CMP:%.*]] = icmp ult i128 [[SHL1]], -10384593717069655257060992658440192
53 // CHECK-NEXT:    [[RES:%.*]] = zext i1 [[CMP]] to i32
54 // CHECK-NEXT:    call void @p(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
55 // CHECK-NEXT:    ret void
56 //
test_long_double_isfinite(long double ld)57 void test_long_double_isfinite(long double ld) {
58   P(isfinite, (ld));
59 
60   return;
61 }
62 
63 // CHECK-LABEL: @test_long_double_isnan(
64 // CHECK-NEXT:  entry:
65 // CHECK-NEXT:    [[LD_ADDR:%.*]] = alloca fp128, align 16
66 // CHECK-NEXT:    store fp128 [[D:%.*]], fp128* [[LD_ADDR]], align 16
67 // CHECK-NEXT:    [[TMP0:%.*]] = load fp128, fp128* [[LD_ADDR]], align 16
68 // CHECK-NEXT:    [[BITCAST:%.*]] = bitcast fp128 [[TMP0]] to i128
69 // CHECK-NEXT:    [[ABS:%.*]] = and i128 [[BITCAST]], 170141183460469231731687303715884105727
70 // CHECK-NEXT:    [[TMP1:%.*]] = sub i128 170135991163610696904058773219554885632, [[ABS]]
71 // CHECK-NEXT:    [[ISNAN:%.*]] = lshr i128 [[TMP1]], 127
72 // CHECK-NEXT:    [[RES:%.*]] = trunc i128 [[ISNAN]] to i32
73 // CHECK-NEXT:    call void @p(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[RES]])
74 // CHECK-NEXT:    ret void
75 //
test_long_double_isnan(long double ld)76 void test_long_double_isnan(long double ld) {
77   P(isnan, (ld));
78 
79   return;
80 }
81