1 ; Test 32-bit subtraction 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(i32 %dummy, i32 %a, i32 *%res) {
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
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
24 ; Check the high end of the ALHSIK range.
25 define zeroext i1 @f2(i32 %dummy, i32 %a, i32 *%res) {
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
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
40 ; Check the next value down, which must use SLFI instead.
41 define zeroext i1 @f3(i32 %dummy, i32 %a, i32 *%res) {
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
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
56 ; Check the high end of the negative ALHSIK range.
57 define zeroext i1 @f4(i32 %dummy, i32 %a, i32 *%res) {
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
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
72 ; Check the low end of the ALHSIK range.
73 define zeroext i1 @f5(i32 %dummy, i32 %a, i32 *%res) {
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
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
88 ; Check the next value down, which must use SLFI instead.
89 define zeroext i1 @f6(i32 %dummy, i32 %a, i32 *%res) {
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
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
104 ; Check using the overflow result for a branch.
105 define void @f7(i32 %dummy, i32 %a, i32 *%res) {
107 ; CHECK: alhsik [[REG1:%r[0-5]]], %r3, -1
108 ; CHECK-DAG: st [[REG1]], 0(%r4)
109 ; CHECK: jgle foo@PLT
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
125 ; ... and the same with the inverted direction.
126 define void @f8(i32 %dummy, i32 %a, i32 *%res) {
128 ; CHECK: alhsik [[REG1:%r[0-5]]], %r3, -1
129 ; CHECK-DAG: st [[REG1]], 0(%r4)
130 ; CHECK: jgnle foo@PLT
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
147 declare {i32, i1} @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone