1; Test 64-bit square root. 2; 3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s 4 5declare double @llvm.sqrt.f64(double %f) 6declare double @sqrt(double) 7 8; Check register square root. 9define double @f1(double %val) { 10; CHECK-LABEL: f1: 11; CHECK: sqdbr %f0, %f0 12; CHECK: br %r14 13 %res = call double @llvm.sqrt.f64(double %val) 14 ret double %res 15} 16 17; Check the low end of the SQDB range. 18define double @f2(double *%ptr) { 19; CHECK-LABEL: f2: 20; CHECK: sqdb %f0, 0(%r2) 21; CHECK: br %r14 22 %val = load double , double *%ptr 23 %res = call double @llvm.sqrt.f64(double %val) 24 ret double %res 25} 26 27; Check the high end of the aligned SQDB range. 28define double @f3(double *%base) { 29; CHECK-LABEL: f3: 30; CHECK: sqdb %f0, 4088(%r2) 31; CHECK: br %r14 32 %ptr = getelementptr double, double *%base, i64 511 33 %val = load double , double *%ptr 34 %res = call double @llvm.sqrt.f64(double %val) 35 ret double %res 36} 37 38; Check the next doubleword up, which needs separate address logic. 39; Other sequences besides this one would be OK. 40define double @f4(double *%base) { 41; CHECK-LABEL: f4: 42; CHECK: aghi %r2, 4096 43; CHECK: sqdb %f0, 0(%r2) 44; CHECK: br %r14 45 %ptr = getelementptr double, double *%base, i64 512 46 %val = load double , double *%ptr 47 %res = call double @llvm.sqrt.f64(double %val) 48 ret double %res 49} 50 51; Check negative displacements, which also need separate address logic. 52define double @f5(double *%base) { 53; CHECK-LABEL: f5: 54; CHECK: aghi %r2, -8 55; CHECK: sqdb %f0, 0(%r2) 56; CHECK: br %r14 57 %ptr = getelementptr double, double *%base, i64 -1 58 %val = load double , double *%ptr 59 %res = call double @llvm.sqrt.f64(double %val) 60 ret double %res 61} 62 63; Check that SQDB allows indices. 64define double @f6(double *%base, i64 %index) { 65; CHECK-LABEL: f6: 66; CHECK: sllg %r1, %r3, 3 67; CHECK: sqdb %f0, 800(%r1,%r2) 68; CHECK: br %r14 69 %ptr1 = getelementptr double, double *%base, i64 %index 70 %ptr2 = getelementptr double, double *%ptr1, i64 100 71 %val = load double , double *%ptr2 72 %res = call double @llvm.sqrt.f64(double %val) 73 ret double %res 74} 75 76; Test a case where we spill the source of at least one SQDBR. We want 77; to use SQDB if possible. 78define void @f7(double *%ptr) { 79; CHECK-LABEL: f7: 80; CHECK: sqdb {{%f[0-9]+}}, 160(%r15) 81; CHECK: br %r14 82 %val0 = load volatile double , double *%ptr 83 %val1 = load volatile double , double *%ptr 84 %val2 = load volatile double , double *%ptr 85 %val3 = load volatile double , double *%ptr 86 %val4 = load volatile double , double *%ptr 87 %val5 = load volatile double , double *%ptr 88 %val6 = load volatile double , double *%ptr 89 %val7 = load volatile double , double *%ptr 90 %val8 = load volatile double , double *%ptr 91 %val9 = load volatile double , double *%ptr 92 %val10 = load volatile double , double *%ptr 93 %val11 = load volatile double , double *%ptr 94 %val12 = load volatile double , double *%ptr 95 %val13 = load volatile double , double *%ptr 96 %val14 = load volatile double , double *%ptr 97 %val15 = load volatile double , double *%ptr 98 %val16 = load volatile double , double *%ptr 99 100 %sqrt0 = call double @llvm.sqrt.f64(double %val0) 101 %sqrt1 = call double @llvm.sqrt.f64(double %val1) 102 %sqrt2 = call double @llvm.sqrt.f64(double %val2) 103 %sqrt3 = call double @llvm.sqrt.f64(double %val3) 104 %sqrt4 = call double @llvm.sqrt.f64(double %val4) 105 %sqrt5 = call double @llvm.sqrt.f64(double %val5) 106 %sqrt6 = call double @llvm.sqrt.f64(double %val6) 107 %sqrt7 = call double @llvm.sqrt.f64(double %val7) 108 %sqrt8 = call double @llvm.sqrt.f64(double %val8) 109 %sqrt9 = call double @llvm.sqrt.f64(double %val9) 110 %sqrt10 = call double @llvm.sqrt.f64(double %val10) 111 %sqrt11 = call double @llvm.sqrt.f64(double %val11) 112 %sqrt12 = call double @llvm.sqrt.f64(double %val12) 113 %sqrt13 = call double @llvm.sqrt.f64(double %val13) 114 %sqrt14 = call double @llvm.sqrt.f64(double %val14) 115 %sqrt15 = call double @llvm.sqrt.f64(double %val15) 116 %sqrt16 = call double @llvm.sqrt.f64(double %val16) 117 118 store volatile double %val0, double *%ptr 119 store volatile double %val1, double *%ptr 120 store volatile double %val2, double *%ptr 121 store volatile double %val3, double *%ptr 122 store volatile double %val4, double *%ptr 123 store volatile double %val5, double *%ptr 124 store volatile double %val6, double *%ptr 125 store volatile double %val7, double *%ptr 126 store volatile double %val8, double *%ptr 127 store volatile double %val9, double *%ptr 128 store volatile double %val10, double *%ptr 129 store volatile double %val11, double *%ptr 130 store volatile double %val12, double *%ptr 131 store volatile double %val13, double *%ptr 132 store volatile double %val14, double *%ptr 133 store volatile double %val15, double *%ptr 134 store volatile double %val16, double *%ptr 135 136 store volatile double %sqrt0, double *%ptr 137 store volatile double %sqrt1, double *%ptr 138 store volatile double %sqrt2, double *%ptr 139 store volatile double %sqrt3, double *%ptr 140 store volatile double %sqrt4, double *%ptr 141 store volatile double %sqrt5, double *%ptr 142 store volatile double %sqrt6, double *%ptr 143 store volatile double %sqrt7, double *%ptr 144 store volatile double %sqrt8, double *%ptr 145 store volatile double %sqrt9, double *%ptr 146 store volatile double %sqrt10, double *%ptr 147 store volatile double %sqrt11, double *%ptr 148 store volatile double %sqrt12, double *%ptr 149 store volatile double %sqrt13, double *%ptr 150 store volatile double %sqrt14, double *%ptr 151 store volatile double %sqrt15, double *%ptr 152 store volatile double %sqrt16, double *%ptr 153 154 ret void 155} 156 157; Check that a call to the normal sqrt function is lowered. 158define double @f8(double %dummy, double %val) { 159; CHECK-LABEL: f8: 160; CHECK: sqdbr %f0, %f2 161; CHECK: cdbr %f0, %f0 162; CHECK: jo [[LABEL:\.L.*]] 163; CHECK: br %r14 164; CHECK: [[LABEL]]: 165; CHECK: ldr %f0, %f2 166; CHECK: jg sqrt@PLT 167 %res = tail call double @sqrt(double %val) 168 ret double %res 169} 170