1; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -mtriple=systemz-unknown -mcpu=z13 | FileCheck %s --check-prefixes=CHECK,Z13 2; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -mtriple=systemz-unknown -mcpu=arch15 | FileCheck %s --check-prefixes=CHECK,ARC15 3; 4 5define i128 @fun1(i128 %val1, i128 %val2) { 6; CHECK-LABEL: 'fun1' 7; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %cmp = icmp eq i128 %val1, %val2 8; Z13: Cost Model: Found an estimated cost of 5 for instruction: %v128 = sext i1 %cmp to i128 9; ARC15: Cost Model: Found an estimated cost of 0 for instruction: %v128 = sext i1 %cmp to i128 10 %cmp = icmp eq i128 %val1, %val2 11 %v128 = sext i1 %cmp to i128 12 ret i128 %v128 13} 14 15define i128 @fun2(i128 %val1, i128 %val2) { 16; CHECK-LABEL: 'fun2' 17; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %cmp = icmp eq i128 %val1, %val2 18; CHECK: Cost Model: Found an estimated cost of 5 for instruction: %v128 = zext i1 %cmp to i128 19 %cmp = icmp eq i128 %val1, %val2 20 %v128 = zext i1 %cmp to i128 21 ret i128 %v128 22} 23 24define i128 @fun3(i128 %val1, i128 %val2, 25 i128 %val3, i128 %val4) { 26; CHECK-LABEL: 'fun3' 27; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %cmp = icmp eq i128 %val1, %val2 28; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %add = add i128 %val3, %val4 29; Z13: Cost Model: Found an estimated cost of 4 for instruction: %sel = select i1 %cmp, i128 %val3, i128 %add 30; ARC15: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %cmp, i128 %val3, i128 %add 31 %cmp = icmp eq i128 %val1, %val2 32 %add = add i128 %val3, %val4 33 %sel = select i1 %cmp, i128 %val3, i128 %add 34 ret i128 %sel 35} 36 37define i64 @fun3_sel64(i128 %val1, i128 %val2, 38 i64 %val3, i64 %val4) { 39; CHECK-LABEL: 'fun3_sel64' 40; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %cmp = icmp ugt i128 %val1, %val2 41; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %add = add i64 %val3, %val4 42; Z13: Cost Model: Found an estimated cost of 4 for instruction: %sel = select i1 %cmp, i64 %val3, i64 %add 43; ARC15: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %cmp, i64 %val3, i64 %add 44 %cmp = icmp ugt i128 %val1, %val2 45 %add = add i64 %val3, %val4 46 %sel = select i1 %cmp, i64 %val3, i64 %add 47 ret i64 %sel 48} 49 50define i128 @fun3_cmp64(i64 %val1, i64 %val2, 51 i128 %val3, i128 %val4) { 52; CHECK-LABEL: 'fun3_cmp64' 53; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %cmp = icmp slt i64 %val1, %val2 54; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %add = add i128 %val3, %val4 55; CHECk: Cost Model: Found an estimated cost of 4 for instruction: %sel = select i1 %cmp, i128 %val3, i128 %add 56 %cmp = icmp slt i64 %val1, %val2 57 %add = add i128 %val3, %val4 58 %sel = select i1 %cmp, i128 %val3, i128 %add 59 ret i128 %sel 60} 61 62define i128 @fun4(ptr %src) { 63; CHECK-LABEL: 'fun4' 64; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %res = sext i64 %v to i128 65 %v = load i64, ptr %src, align 8 66 %res = sext i64 %v to i128 67 ret i128 %res 68} 69 70define i128 @fun5(i64 %lhs, i64 %rhs) { 71; CHECK-LABEL: 'fun5' 72; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %res = sext i64 %v to i128 73 %v = add i64 %lhs, %rhs 74 %res = sext i64 %v to i128 75 ret i128 %res 76} 77 78define i128 @fun6(ptr %src) { 79; CHECK-LABEL: 'fun6' 80; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %res = zext i64 %v to i128 81 %v = load i64, ptr %src, align 8 82 %res = zext i64 %v to i128 83 ret i128 %res 84} 85 86define i128 @fun7(i64 %lhs, i64 %rhs) { 87; CHECK-LABEL: 'fun7' 88; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %res = zext i64 %v to i128 89 %v = add i64 %lhs, %rhs 90 %res = zext i64 %v to i128 91 ret i128 %res 92} 93 94; Truncating store is free. 95define void @fun8(i128 %lhs, i128 %rhs, ptr %dst) { 96; CHECK-LABEL: 'fun8' 97; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %t = trunc i128 %v to i64 98 %v = add i128 %lhs, %rhs 99 %t = trunc i128 %v to i64 100 store i64 %t, ptr %dst, align 8 101 ret void 102} 103 104; If there is a non-store user, an extraction is needed. 105define i64 @fun9(i128 %lhs, i128 %rhs, ptr %dst) { 106; CHECK-LABEL: 'fun9' 107; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %t = trunc i128 %v to i64 108 %v = add i128 %lhs, %rhs 109 %t = trunc i128 %v to i64 110 store i64 %t, ptr %dst, align 8 111 ret i64 %t 112} 113 114; Truncation of load is free. 115define i64 @fun10(ptr %src) { 116; CHECK-LABEL: 'fun10' 117; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %t = trunc i128 %v to i64 118 %v = load i128, ptr %src, align 8 119 %t = trunc i128 %v to i64 120 ret i64 %t 121} 122 123; If the load has another user, the truncation becomes an extract. 124define i64 @fun11(ptr %src, i128 %val2, ptr %dst) { 125; CHECK-LABEL: 'fun11' 126; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %t = trunc i128 %v to i64 127 %v = load i128, ptr %src, align 8 128 %t = trunc i128 %v to i64 129 %a = add i128 %v, %val2 130 store i128 %a, ptr %dst 131 ret i64 %t 132} 133 134; Trunction with a GPR use typically requires an extraction. 135define i64 @fun12(i128 %lhs, i128 %rhs) { 136; CHECK-LABEL: 'fun12' 137; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %t = trunc i128 %v to i64 138 %v = add i128 %lhs, %rhs 139 %t = trunc i128 %v to i64 140 ret i64 %t 141} 142 143; Fp<->Int conversions require libcalls. 144define void @fun13() { 145; CHECK-LABEL: 'fun13' 146; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v0 = fptosi fp128 undef to i128 147; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v1 = fptosi double undef to i128 148; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v2 = fptosi float undef to i128 149; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v3 = fptoui fp128 undef to i128 150; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v4 = fptoui double undef to i128 151; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v5 = fptoui float undef to i128 152; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v6 = sitofp i128 undef to fp128 153; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v7 = sitofp i128 undef to double 154; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v8 = sitofp i128 undef to float 155; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v9 = uitofp i128 undef to fp128 156; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v10 = uitofp i128 undef to double 157; CHECK: Cost Model: Found an estimated cost of 30 for instruction: %v11 = uitofp i128 undef to float 158 %v0 = fptosi fp128 undef to i128 159 %v1 = fptosi double undef to i128 160 %v2 = fptosi float undef to i128 161 %v3 = fptoui fp128 undef to i128 162 %v4 = fptoui double undef to i128 163 %v5 = fptoui float undef to i128 164 %v6 = sitofp i128 undef to fp128 165 %v7 = sitofp i128 undef to double 166 %v8 = sitofp i128 undef to float 167 %v9 = uitofp i128 undef to fp128 168 %v10 = uitofp i128 undef to double 169 %v11 = uitofp i128 undef to float 170 ret void 171} 172