1; Test 64-bit addition in which the second operand is constant and in which 2; three-operand forms are available. 3; 4; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z196 | FileCheck %s 5 6declare i64 @foo() 7 8; Check subtraction of 1. 9define zeroext i1 @f1(i64 %dummy, i64 %a, i64 *%res) { 10; CHECK-LABEL: f1: 11; CHECK: alghsik [[REG1:%r[0-5]]], %r3, -1 12; CHECK-DAG: stg [[REG1]], 0(%r4) 13; CHECK-DAG: ipm [[REG2:%r[0-5]]] 14; CHECK-DAG: afi [[REG2]], -536870912 15; CHECK-DAG: risbg %r2, [[REG2]], 63, 191, 33 16; CHECK: br %r14 17 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 1) 18 %val = extractvalue {i64, i1} %t, 0 19 %obit = extractvalue {i64, i1} %t, 1 20 store i64 %val, i64 *%res 21 ret i1 %obit 22} 23 24; Check the high end of the ALGHSIK range. 25define zeroext i1 @f2(i64 %dummy, i64 %a, i64 *%res) { 26; CHECK-LABEL: f2: 27; CHECK: alghsik [[REG1:%r[0-5]]], %r3, -32768 28; CHECK-DAG: stg [[REG1]], 0(%r4) 29; CHECK-DAG: ipm [[REG2:%r[0-5]]] 30; CHECK-DAG: afi [[REG2]], -536870912 31; CHECK-DAG: risbg %r2, [[REG2]], 63, 191, 33 32; CHECK: br %r14 33 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 32768) 34 %val = extractvalue {i64, i1} %t, 0 35 %obit = extractvalue {i64, i1} %t, 1 36 store i64 %val, i64 *%res 37 ret i1 %obit 38} 39 40; Check the next value up, which must use SLGFI instead. 41define zeroext i1 @f3(i64 %dummy, i64 %a, i64 *%res) { 42; CHECK-LABEL: f3: 43; CHECK: slgfi %r3, 32769 44; CHECK-DAG: stg %r3, 0(%r4) 45; CHECK-DAG: ipm [[REG2:%r[0-5]]] 46; CHECK-DAG: afi [[REG2]], -536870912 47; CHECK-DAG: risbg %r2, [[REG2]], 63, 191, 33 48; CHECK: br %r14 49 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 32769) 50 %val = extractvalue {i64, i1} %t, 0 51 %obit = extractvalue {i64, i1} %t, 1 52 store i64 %val, i64 *%res 53 ret i1 %obit 54} 55 56; Check the high end of the negative ALGHSIK range. 57define zeroext i1 @f4(i64 %dummy, i64 %a, i64 *%res) { 58; CHECK-LABEL: f4: 59; CHECK: alghsik [[REG1:%r[0-5]]], %r3, 1 60; CHECK-DAG: stg [[REG1]], 0(%r4) 61; CHECK-DAG: ipm [[REG2:%r[0-5]]] 62; CHECK-DAG: afi [[REG2]], -536870912 63; CHECK-DAG: risbg %r2, [[REG2]], 63, 191, 33 64; CHECK: br %r14 65 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 -1) 66 %val = extractvalue {i64, i1} %t, 0 67 %obit = extractvalue {i64, i1} %t, 1 68 store i64 %val, i64 *%res 69 ret i1 %obit 70} 71 72; Check the low end of the ALGHSIK range. 73define zeroext i1 @f5(i64 %dummy, i64 %a, i64 *%res) { 74; CHECK-LABEL: f5: 75; CHECK: alghsik [[REG1:%r[0-5]]], %r3, 32767 76; CHECK-DAG: stg [[REG1]], 0(%r4) 77; CHECK-DAG: ipm [[REG2:%r[0-5]]] 78; CHECK-DAG: afi [[REG2]], -536870912 79; CHECK-DAG: risbg %r2, [[REG2]], 63, 191, 33 80; CHECK: br %r14 81 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 -32767) 82 %val = extractvalue {i64, i1} %t, 0 83 %obit = extractvalue {i64, i1} %t, 1 84 store i64 %val, i64 *%res 85 ret i1 %obit 86} 87 88; Test the next value down, which cannot use either ALGHSIK or SLGFI. 89define zeroext i1 @f6(i64 %dummy, i64 %a, i64 *%res) { 90; CHECK-LABEL: f6: 91; CHECK-NOT: alghsik 92; CHECK-NOT: slgfi 93; CHECK: br %r14 94 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 -32768) 95 %val = extractvalue {i64, i1} %t, 0 96 %obit = extractvalue {i64, i1} %t, 1 97 store i64 %val, i64 *%res 98 ret i1 %obit 99} 100 101; Check using the overflow result for a branch. 102define void @f7(i64 %dummy, i64 %a, i64 *%res) { 103; CHECK-LABEL: f7: 104; CHECK: alghsik [[REG1:%r[0-5]]], %r3, -1 105; CHECK-DAG: stg [[REG1]], 0(%r4) 106; CHECK: jgle foo@PLT 107; CHECK: br %r14 108 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 1) 109 %val = extractvalue {i64, i1} %t, 0 110 %obit = extractvalue {i64, i1} %t, 1 111 store i64 %val, i64 *%res 112 br i1 %obit, label %call, label %exit 113 114call: 115 tail call i64 @foo() 116 br label %exit 117 118exit: 119 ret void 120} 121 122; ... and the same with the inverted direction. 123define void @f8(i64 %dummy, i64 %a, i64 *%res) { 124; CHECK-LABEL: f8: 125; CHECK: alghsik [[REG1:%r[0-5]]], %r3, -1 126; CHECK-DAG: stg [[REG1]], 0(%r4) 127; CHECK: jgnle foo@PLT 128; CHECK: br %r14 129 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 1) 130 %val = extractvalue {i64, i1} %t, 0 131 %obit = extractvalue {i64, i1} %t, 1 132 store i64 %val, i64 *%res 133 br i1 %obit, label %exit, label %call 134 135call: 136 tail call i64 @foo() 137 br label %exit 138 139exit: 140 ret void 141} 142 143 144declare {i64, i1} @llvm.usub.with.overflow.i64(i64, i64) nounwind readnone 145 146