1 // RUN: %clang -Xclang -no-opaque-pointers -std=c++11 --target=aarch64-arm--eabi -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH64 2 3 /* Various contexts where type _Float16 can appear. */ 4 5 6 /* Namespace */ 7 8 namespace { 9 _Float16 f1n; 10 // CHECK-DAG: @_ZN12_GLOBAL__N_13f1nE = internal global half 0xH0000, align 2 11 12 _Float16 f2n = 33.f16; 13 // CHECK-DAG: @_ZN12_GLOBAL__N_13f2nE = internal global half 0xH5020, align 2 14 15 _Float16 arr1n[10]; 16 // CHECK-AARCH64-DAG: @_ZN12_GLOBAL__N_15arr1nE = internal global [10 x half] zeroinitializer, align 2 17 18 _Float16 arr2n[] = { 1.2, 3.0, 3.e4 }; 19 // CHECK-DAG: @_ZN12_GLOBAL__N_15arr2nE = internal global [3 x half] [half 0xH3CCD, half 0xH4200, half 0xH7753], align 2 20 21 const volatile _Float16 func1n(const _Float16 &arg) { 22 return arg + f2n + arr1n[4] - arr2n[1]; 23 } 24 } 25 26 27 /* File */ 28 29 _Float16 f1f; 30 // CHECK-AARCH64-DAG: @f1f = dso_local global half 0xH0000, align 2 31 32 _Float16 f2f = 32.4; 33 // CHECK-DAG: @f2f = dso_local global half 0xH500D, align 2 34 35 _Float16 arr1f[10]; 36 // CHECK-AARCH64-DAG: @arr1f = dso_local global [10 x half] zeroinitializer, align 2 37 38 _Float16 arr2f[] = { -1.2, -3.0, -3.e4 }; 39 // CHECK-DAG: @arr2f = dso_local global [3 x half] [half 0xHBCCD, half 0xHC200, half 0xHF753], align 2 40 41 _Float16 func1f(_Float16 arg); 42 43 44 /* Class */ 45 46 class C1 { 47 _Float16 f1c; 48 49 static const _Float16 f2c; 50 // CHECK-DAG: @_ZN2C13f2cE = external dso_local constant half, align 2 51 52 volatile _Float16 f3c; 53 54 public: 55 C1(_Float16 arg) : f1c(arg), f3c(arg) { } 56 // Check that we mangle _Float16 to DF16_ 57 // CHECK-DAG: define linkonce_odr dso_local void @_ZN2C1C2EDF16_(%class.C1*{{.*}}, half{{.*}}) 58 59 _Float16 func1c(_Float16 arg ) { 60 return f1c + arg; 61 } 62 // CHECK-DAG: define linkonce_odr dso_local noundef half @_ZN2C16func1cEDF16_(%class.C1*{{.*}}, half{{.*}}) 63 64 static _Float16 func2c(_Float16 arg) { 65 return arg * C1::f2c; 66 } 67 // CHECK-DAG: define linkonce_odr dso_local noundef half @_ZN2C16func2cEDF16_(half{{.*}}) 68 }; 69 70 /* Template */ 71 72 template <class C> C func1t(C arg) { 73 return arg * 2.f16; 74 } 75 // CHECK-DAG: define linkonce_odr dso_local noundef half @_Z6func1tIDF16_ET_S0_(half{{.*}}) 76 77 template <class C> struct S1 { 78 C mem1; 79 }; 80 81 template <> struct S1<_Float16> { 82 _Float16 mem2; 83 }; 84 85 86 /* Local */ 87 88 extern int printf (const char *__restrict __format, ...); 89 90 int main(void) { 91 _Float16 f1l = 1e3f16; 92 // CHECK-DAG: store half 0xH63D0, half* %{{.*}}, align 2 93 94 _Float16 f2l = -0.f16; 95 // CHECK-DAG: store half 0xH8000, half* %{{.*}}, align 2 96 97 _Float16 f3l = 1.000976562; 98 // CHECK-DAG: store half 0xH3C01, half* %{{.*}}, align 2 99 100 C1 c1(f1l); 101 // CHECK-DAG: [[F1L:%[a-z0-9]+]] = load half, half* %{{.*}}, align 2 102 // CHECK-DAG: call void @_ZN2C1C2EDF16_(%class.C1* {{[^,]*}} %{{.*}}, half noundef %{{.*}}) 103 104 S1<_Float16> s1 = { 132.f16 }; 105 // CHECK-DAG: @__const.main.s1 = private unnamed_addr constant %struct.S1 { half 0xH5820 }, align 2 106 // CHECK-DAG: [[S1:%[0-9]+]] = bitcast %struct.S1* %{{.*}} to i8* 107 // CHECK-DAG: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 2 [[S1]], i8* align 2 bitcast (%struct.S1* @__const.main.s1 to i8*), i64 2, i1 false) 108 109 _Float16 f4l = func1n(f1l) + func1f(f2l) + c1.func1c(f3l) + c1.func2c(f1l) + 110 func1t(f1l) + s1.mem2 - f1n + f2n; 111 112 auto f5l = -1.f16, *f6l = &f2l, f7l = func1t(f3l); 113 // CHECK-DAG: store half 0xHBC00, half* %{{.*}}, align 2 114 // CHECK-DAG: store half* %{{.*}}, half** %{{.*}}, align 8 115 116 _Float16 f8l = f4l++; 117 // CHECK-DAG: %{{.*}} = load half, half* %{{.*}}, align 2 118 // CHECK-DAG: [[INC:%[a-z0-9]+]] = fadd half {{.*}}, 0xH3C00 119 // CHECK-DAG: store half [[INC]], half* %{{.*}}, align 2 120 121 _Float16 arr1l[] = { -1.f16, -0.f16, -11.f16 }; 122 // CHECK-DAG: @__const.main.arr1l = private unnamed_addr constant [3 x half] [half 0xHBC00, half 0xH8000, half 0xHC980], align 2 123 124 float cvtf = f2n; 125 //CHECK-DAG: [[H2F:%[a-z0-9]+]] = fpext half {{%[0-9]+}} to float 126 //CHECK-DAG: store float [[H2F]], float* %{{.*}}, align 4 127 128 double cvtd = f2n; 129 //CHECK-DAG: [[H2D:%[a-z0-9]+]] = fpext half {{%[0-9]+}} to double 130 //CHECK-DAG: store double [[H2D]], double* %{{.*}}, align 8 131 132 133 long double cvtld = f2n; 134 //CHECK-AARCh64-DAG: [[H2LD:%[a-z0-9]+]] = fpext half {{%[0-9]+}} to fp128 135 //CHECK-AARCh64-DAG: store fp128 [[H2LD]], fp128* %{{.*}}, align 16 136 137 _Float16 f2h = 42.0f; 138 //CHECK-DAG: store half 0xH5140, half* %{{.*}}, align 2 139 _Float16 d2h = 42.0; 140 //CHECK-DAG: store half 0xH5140, half* %{{.*}}, align 2 141 _Float16 ld2h = 42.0l; 142 //CHECK-DAG:store half 0xH5140, half* %{{.*}}, align 2 143 } 144