1; RUN: llc < %s -O2 -mtriple=x86_64-linux-android -mattr=+mmx | FileCheck %s 2; RUN: llc < %s -O2 -mtriple=x86_64-linux-gnu -mattr=+mmx | FileCheck %s 3 4; Check soft floating point conversion function calls. 5 6@vi32 = common global i32 0, align 4 7@vi64 = common global i64 0, align 8 8@vu32 = common global i32 0, align 4 9@vu64 = common global i64 0, align 8 10@vf32 = common global float 0.000000e+00, align 4 11@vf64 = common global double 0.000000e+00, align 8 12@vf128 = common global fp128 0xL00000000000000000000000000000000, align 16 13 14define void @TestFPExtF32_F128() { 15entry: 16 %0 = load float, float* @vf32, align 4 17 %conv = fpext float %0 to fp128 18 store fp128 %conv, fp128* @vf128, align 16 19 ret void 20; CHECK-LABEL: TestFPExtF32_F128: 21; CHECK: movss vf32(%rip), %xmm0 22; CHECK-NEXT: callq __extendsftf2 23; CHECK-NEXT: movaps %xmm0, vf128(%rip) 24; CHECK: retq 25} 26 27define void @TestFPExtF64_F128() { 28entry: 29 %0 = load double, double* @vf64, align 8 30 %conv = fpext double %0 to fp128 31 store fp128 %conv, fp128* @vf128, align 16 32 ret void 33; CHECK-LABEL: TestFPExtF64_F128: 34; CHECK: movsd vf64(%rip), %xmm0 35; CHECK-NEXT: callq __extenddftf2 36; CHECK-NEXT: movapd %xmm0, vf128(%rip) 37; CHECK: ret 38} 39 40define void @TestFPToSIF128_I32() { 41entry: 42 %0 = load fp128, fp128* @vf128, align 16 43 %conv = fptosi fp128 %0 to i32 44 store i32 %conv, i32* @vi32, align 4 45 ret void 46; CHECK-LABEL: TestFPToSIF128_I32: 47; CHECK: movaps vf128(%rip), %xmm0 48; CHECK-NEXT: callq __fixtfsi 49; CHECK-NEXT: movl %eax, vi32(%rip) 50; CHECK: retq 51} 52 53define void @TestFPToUIF128_U32() { 54entry: 55 %0 = load fp128, fp128* @vf128, align 16 56 %conv = fptoui fp128 %0 to i32 57 store i32 %conv, i32* @vu32, align 4 58 ret void 59; CHECK-LABEL: TestFPToUIF128_U32: 60; CHECK: movaps vf128(%rip), %xmm0 61; CHECK-NEXT: callq __fixunstfsi 62; CHECK-NEXT: movl %eax, vu32(%rip) 63; CHECK: retq 64} 65 66define void @TestFPToSIF128_I64() { 67entry: 68 %0 = load fp128, fp128* @vf128, align 16 69 %conv = fptosi fp128 %0 to i32 70 %conv1 = sext i32 %conv to i64 71 store i64 %conv1, i64* @vi64, align 8 72 ret void 73; CHECK-LABEL: TestFPToSIF128_I64: 74; CHECK: movaps vf128(%rip), %xmm0 75; CHECK-NEXT: callq __fixtfsi 76; CHECK-NEXT: cltq 77; CHECK-NEXT: movq %rax, vi64(%rip) 78; CHECK: retq 79} 80 81define void @TestFPToUIF128_U64() { 82entry: 83 %0 = load fp128, fp128* @vf128, align 16 84 %conv = fptoui fp128 %0 to i32 85 %conv1 = zext i32 %conv to i64 86 store i64 %conv1, i64* @vu64, align 8 87 ret void 88; CHECK-LABEL: TestFPToUIF128_U64: 89; CHECK: movaps vf128(%rip), %xmm0 90; CHECK-NEXT: callq __fixunstfsi 91; CHECK-NEXT: movl %eax, %eax 92; CHECK-NEXT: movq %rax, vu64(%rip) 93; CHECK: retq 94} 95 96define void @TestFPTruncF128_F32() { 97entry: 98 %0 = load fp128, fp128* @vf128, align 16 99 %conv = fptrunc fp128 %0 to float 100 store float %conv, float* @vf32, align 4 101 ret void 102; CHECK-LABEL: TestFPTruncF128_F32: 103; CHECK: movaps vf128(%rip), %xmm0 104; CHECK-NEXT: callq __trunctfsf2 105; CHECK-NEXT: movss %xmm0, vf32(%rip) 106; CHECK: retq 107} 108 109define void @TestFPTruncF128_F64() { 110entry: 111 %0 = load fp128, fp128* @vf128, align 16 112 %conv = fptrunc fp128 %0 to double 113 store double %conv, double* @vf64, align 8 114 ret void 115; CHECK-LABEL: TestFPTruncF128_F64: 116; CHECK: movapd vf128(%rip), %xmm0 117; CHECK-NEXT: callq __trunctfdf2 118; CHECK-NEXT: movsd %xmm0, vf64(%rip) 119; CHECK: retq 120} 121 122define void @TestSIToFPI32_F128() { 123entry: 124 %0 = load i32, i32* @vi32, align 4 125 %conv = sitofp i32 %0 to fp128 126 store fp128 %conv, fp128* @vf128, align 16 127 ret void 128; CHECK-LABEL: TestSIToFPI32_F128: 129; CHECK: movl vi32(%rip), %edi 130; CHECK-NEXT: callq __floatsitf 131; CHECK-NEXT: movaps %xmm0, vf128(%rip) 132; CHECK: retq 133} 134 135define void @TestUIToFPU32_F128() #2 { 136entry: 137 %0 = load i32, i32* @vu32, align 4 138 %conv = uitofp i32 %0 to fp128 139 store fp128 %conv, fp128* @vf128, align 16 140 ret void 141; CHECK-LABEL: TestUIToFPU32_F128: 142; CHECK: movl vu32(%rip), %edi 143; CHECK-NEXT: callq __floatunsitf 144; CHECK-NEXT: movaps %xmm0, vf128(%rip) 145; CHECK: retq 146} 147 148define void @TestSIToFPI64_F128(){ 149entry: 150 %0 = load i64, i64* @vi64, align 8 151 %conv = sitofp i64 %0 to fp128 152 store fp128 %conv, fp128* @vf128, align 16 153 ret void 154; CHECK-LABEL: TestSIToFPI64_F128: 155; CHECK: movq vi64(%rip), %rdi 156; CHECK-NEXT: callq __floatditf 157; CHECK-NEXT: movaps %xmm0, vf128(%rip) 158; CHECK: retq 159} 160 161define void @TestUIToFPU64_F128() #2 { 162entry: 163 %0 = load i64, i64* @vu64, align 8 164 %conv = uitofp i64 %0 to fp128 165 store fp128 %conv, fp128* @vf128, align 16 166 ret void 167; CHECK-LABEL: TestUIToFPU64_F128: 168; CHECK: movq vu64(%rip), %rdi 169; CHECK-NEXT: callq __floatunditf 170; CHECK-NEXT: movaps %xmm0, vf128(%rip) 171; CHECK: retq 172} 173 174define i32 @TestConst128(fp128 %v) { 175entry: 176 %cmp = fcmp ogt fp128 %v, 0xL00000000000000003FFF000000000000 177 %conv = zext i1 %cmp to i32 178 ret i32 %conv 179; CHECK-LABEL: TestConst128: 180; CHECK: movaps {{.*}}, %xmm1 181; CHECK-NEXT: callq __gttf2 182; CHECK-NEXT: test 183; CHECK: retq 184} 185 186; C code: 187; struct TestBits_ieee_ext { 188; unsigned v1; 189; unsigned v2; 190; }; 191; union TestBits_LDU { 192; FP128 ld; 193; struct TestBits_ieee_ext bits; 194; }; 195; int TestBits128(FP128 ld) { 196; union TestBits_LDU u; 197; u.ld = ld * ld; 198; return ((u.bits.v1 | u.bits.v2) == 0); 199; } 200define i32 @TestBits128(fp128 %ld) { 201entry: 202 %mul = fmul fp128 %ld, %ld 203 %0 = bitcast fp128 %mul to i128 204 %shift = lshr i128 %0, 32 205 %or5 = or i128 %shift, %0 206 %or = trunc i128 %or5 to i32 207 %cmp = icmp eq i32 %or, 0 208 %conv = zext i1 %cmp to i32 209 ret i32 %conv 210; CHECK-LABEL: TestBits128: 211; CHECK: movaps %xmm0, %xmm1 212; CHECK-NEXT: callq __multf3 213; CHECK-NEXT: movaps %xmm0, (%rsp) 214; CHECK-NEXT: movq (%rsp), 215; CHECK-NEXT: movq % 216; CHECK-NEXT: shrq $32, 217; CHECK: orl 218; CHECK-NEXT: sete %al 219; CHECK-NEXT: movzbl %al, %eax 220; CHECK: retq 221; 222; If TestBits128 fails due to any llvm or clang change, 223; please make sure the original simplified C code will 224; be compiled into correct IL and assembly code, not 225; just this TestBits128 test case. Better yet, try to 226; test the whole libm and its test cases. 227} 228 229; C code: (compiled with -target x86_64-linux-android) 230; typedef long double __float128; 231; __float128 TestPair128(unsigned long a, unsigned long b) { 232; unsigned __int128 n; 233; unsigned __int128 v1 = ((unsigned __int128)a << 64); 234; unsigned __int128 v2 = (unsigned __int128)b; 235; n = (v1 | v2) + 3; 236; return *(__float128*)&n; 237; } 238define fp128 @TestPair128(i64 %a, i64 %b) { 239entry: 240 %conv = zext i64 %a to i128 241 %shl = shl nuw i128 %conv, 64 242 %conv1 = zext i64 %b to i128 243 %or = or i128 %shl, %conv1 244 %add = add i128 %or, 3 245 %0 = bitcast i128 %add to fp128 246 ret fp128 %0 247; CHECK-LABEL: TestPair128: 248; CHECK: addq $3, %rsi 249; CHECK: movq %rsi, -24(%rsp) 250; CHECK: movq %rdi, -16(%rsp) 251; CHECK: movaps -24(%rsp), %xmm0 252; CHECK-NEXT: retq 253} 254 255define fp128 @TestTruncCopysign(fp128 %x, i32 %n) { 256entry: 257 %cmp = icmp sgt i32 %n, 50000 258 br i1 %cmp, label %if.then, label %cleanup 259 260if.then: ; preds = %entry 261 %conv = fptrunc fp128 %x to double 262 %call = tail call double @copysign(double 0x7FF0000000000000, double %conv) #2 263 %conv1 = fpext double %call to fp128 264 br label %cleanup 265 266cleanup: ; preds = %entry, %if.then 267 %retval.0 = phi fp128 [ %conv1, %if.then ], [ %x, %entry ] 268 ret fp128 %retval.0 269; CHECK-LABEL: TestTruncCopysign: 270; CHECK: callq __trunctfdf2 271; CHECK-NEXT: andpd {{.*}}, %xmm0 272; CHECK-NEXT: orpd {{.*}}, %xmm0 273; CHECK-NEXT: callq __extenddftf2 274; CHECK: retq 275} 276 277declare double @copysign(double, double) #1 278 279attributes #2 = { nounwind readnone } 280