1; Test 32-bit subtraction 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 i32 @foo() 7 8; Check subtraction of 1. 9define zeroext i1 @f1(i32 %dummy, i32 %a, i32 *%res) { 10; CHECK-LABEL: f1: 11; CHECK: alhsik [[REG1:%r[0-5]]], %r3, -1 12; CHECK-DAG: st [[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 {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 1) 18 %val = extractvalue {i32, i1} %t, 0 19 %obit = extractvalue {i32, i1} %t, 1 20 store i32 %val, i32 *%res 21 ret i1 %obit 22} 23 24; Check the high end of the ALHSIK range. 25define zeroext i1 @f2(i32 %dummy, i32 %a, i32 *%res) { 26; CHECK-LABEL: f2: 27; CHECK: alhsik [[REG1:%r[0-5]]], %r3, -32768 28; CHECK-DAG: st [[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 {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 32768) 34 %val = extractvalue {i32, i1} %t, 0 35 %obit = extractvalue {i32, i1} %t, 1 36 store i32 %val, i32 *%res 37 ret i1 %obit 38} 39 40; Check the next value down, which must use SLFI instead. 41define zeroext i1 @f3(i32 %dummy, i32 %a, i32 *%res) { 42; CHECK-LABEL: f3: 43; CHECK: slfi %r3, 32769 44; CHECK-DAG: st %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 {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 32769) 50 %val = extractvalue {i32, i1} %t, 0 51 %obit = extractvalue {i32, i1} %t, 1 52 store i32 %val, i32 *%res 53 ret i1 %obit 54} 55 56; Check the high end of the negative ALHSIK range. 57define zeroext i1 @f4(i32 %dummy, i32 %a, i32 *%res) { 58; CHECK-LABEL: f4: 59; CHECK: alhsik [[REG1:%r[0-5]]], %r3, 1 60; CHECK-DAG: st [[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 {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 -1) 66 %val = extractvalue {i32, i1} %t, 0 67 %obit = extractvalue {i32, i1} %t, 1 68 store i32 %val, i32 *%res 69 ret i1 %obit 70} 71 72; Check the low end of the ALHSIK range. 73define zeroext i1 @f5(i32 %dummy, i32 %a, i32 *%res) { 74; CHECK-LABEL: f5: 75; CHECK: alhsik [[REG1:%r[0-5]]], %r3, 32767 76; CHECK-DAG: st [[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 {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 -32767) 82 %val = extractvalue {i32, i1} %t, 0 83 %obit = extractvalue {i32, i1} %t, 1 84 store i32 %val, i32 *%res 85 ret i1 %obit 86} 87 88; Check the next value down, which must use SLFI instead. 89define zeroext i1 @f6(i32 %dummy, i32 %a, i32 *%res) { 90; CHECK-LABEL: f6: 91; CHECK: slfi %r3, 4294934528 92; CHECK-DAG: st %r3, 0(%r4) 93; CHECK-DAG: ipm [[REG2:%r[0-5]]] 94; CHECK-DAG: afi [[REG2]], -536870912 95; CHECK-DAG: risbg %r2, [[REG2]], 63, 191, 33 96; CHECK: br %r14 97 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 -32768) 98 %val = extractvalue {i32, i1} %t, 0 99 %obit = extractvalue {i32, i1} %t, 1 100 store i32 %val, i32 *%res 101 ret i1 %obit 102} 103 104; Check using the overflow result for a branch. 105define void @f7(i32 %dummy, i32 %a, i32 *%res) { 106; CHECK-LABEL: f7: 107; CHECK: alhsik [[REG1:%r[0-5]]], %r3, -1 108; CHECK-DAG: st [[REG1]], 0(%r4) 109; CHECK: jgle foo@PLT 110; CHECK: br %r14 111 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 1) 112 %val = extractvalue {i32, i1} %t, 0 113 %obit = extractvalue {i32, i1} %t, 1 114 store i32 %val, i32 *%res 115 br i1 %obit, label %call, label %exit 116 117call: 118 tail call i32 @foo() 119 br label %exit 120 121exit: 122 ret void 123} 124 125; ... and the same with the inverted direction. 126define void @f8(i32 %dummy, i32 %a, i32 *%res) { 127; CHECK-LABEL: f8: 128; CHECK: alhsik [[REG1:%r[0-5]]], %r3, -1 129; CHECK-DAG: st [[REG1]], 0(%r4) 130; CHECK: jgnle foo@PLT 131; CHECK: br %r14 132 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 1) 133 %val = extractvalue {i32, i1} %t, 0 134 %obit = extractvalue {i32, i1} %t, 1 135 store i32 %val, i32 *%res 136 br i1 %obit, label %exit, label %call 137 138call: 139 tail call i32 @foo() 140 br label %exit 141 142exit: 143 ret void 144} 145 146 147declare {i32, i1} @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone 148 149