1 ; Test 64-bit addition in which the second operand is constant and in which
2 ; three-operand forms are available.
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z196 | FileCheck %s
8 ; Check subtraction of 1.
9 define zeroext i1 @f1(i64 %dummy, i64 %a, i64 *%res) {
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
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
24 ; Check the high end of the ALGHSIK range.
25 define zeroext i1 @f2(i64 %dummy, i64 %a, i64 *%res) {
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
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
40 ; Check the next value up, which must use SLGFI instead.
41 define zeroext i1 @f3(i64 %dummy, i64 %a, i64 *%res) {
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
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
56 ; Check the high end of the negative ALGHSIK range.
57 define zeroext i1 @f4(i64 %dummy, i64 %a, i64 *%res) {
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
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
72 ; Check the low end of the ALGHSIK range.
73 define zeroext i1 @f5(i64 %dummy, i64 %a, i64 *%res) {
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
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
88 ; Test the next value down, which cannot use either ALGHSIK or SLGFI.
89 define zeroext i1 @f6(i64 %dummy, i64 %a, i64 *%res) {
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
101 ; Check using the overflow result for a branch.
102 define void @f7(i64 %dummy, i64 %a, i64 *%res) {
104 ; CHECK: alghsik [[REG1:%r[0-5]]], %r3, -1
105 ; CHECK-DAG: stg [[REG1]], 0(%r4)
106 ; CHECK: jgle foo@PLT
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
122 ; ... and the same with the inverted direction.
123 define void @f8(i64 %dummy, i64 %a, i64 *%res) {
125 ; CHECK: alghsik [[REG1:%r[0-5]]], %r3, -1
126 ; CHECK-DAG: stg [[REG1]], 0(%r4)
127 ; CHECK: jgnle foo@PLT
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
144 declare {i64, i1} @llvm.usub.with.overflow.i64(i64, i64) nounwind readnone