1; Test the three-operand form of 32-bit subtraction.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z196 | FileCheck %s
4
5declare i32 @foo(i32, i32, i32)
6
7; Check SLRK.
8define i32 @f1(i32 %dummy, i32 %a, i32 %b, i32 *%flag) {
9; CHECK-LABEL: f1:
10; CHECK: slrk %r2, %r3, %r4
11; CHECK: ipm [[REG:%r[0-5]]]
12; CHECK: afi [[REG]], -536870912
13; CHECK: srl [[REG]], 31
14; CHECK: st [[REG]], 0(%r5)
15; CHECK: br %r14
16  %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
17  %val = extractvalue {i32, i1} %t, 0
18  %obit = extractvalue {i32, i1} %t, 1
19  %ext = zext i1 %obit to i32
20  store i32 %ext, i32 *%flag
21  ret i32 %val
22}
23
24; Check using the overflow result for a branch.
25define i32 @f2(i32 %dummy, i32 %a, i32 %b) {
26; CHECK-LABEL: f2:
27; CHECK: slrk %r2, %r3, %r4
28; CHECK-NEXT: bnler %r14
29; CHECK: lhi %r2, 0
30; CHECK: jg foo@PLT
31  %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
32  %val = extractvalue {i32, i1} %t, 0
33  %obit = extractvalue {i32, i1} %t, 1
34  br i1 %obit, label %call, label %exit
35
36call:
37  %res = tail call i32 @foo(i32 0, i32 %a, i32 %b)
38  ret i32 %res
39
40exit:
41  ret i32 %val
42}
43
44; ... and the same with the inverted direction.
45define i32 @f3(i32 %dummy, i32 %a, i32 %b) {
46; CHECK-LABEL: f3:
47; CHECK: slrk %r2, %r3, %r4
48; CHECK-NEXT: bler %r14
49; CHECK: lhi %r2, 0
50; CHECK: jg foo@PLT
51  %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
52  %val = extractvalue {i32, i1} %t, 0
53  %obit = extractvalue {i32, i1} %t, 1
54  br i1 %obit, label %exit, label %call
55
56call:
57  %res = tail call i32 @foo(i32 0, i32 %a, i32 %b)
58  ret i32 %res
59
60exit:
61  ret i32 %val
62}
63
64; Check that we can still use SLR in obvious cases.
65define i32 @f4(i32 %a, i32 %b, i32 *%flag) {
66; CHECK-LABEL: f4:
67; CHECK: slr %r2, %r3
68; CHECK: ipm [[REG:%r[0-5]]]
69; CHECK: afi [[REG]], -536870912
70; CHECK: srl [[REG]], 31
71; CHECK: st [[REG]], 0(%r4)
72; CHECK: br %r14
73  %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
74  %val = extractvalue {i32, i1} %t, 0
75  %obit = extractvalue {i32, i1} %t, 1
76  %ext = zext i1 %obit to i32
77  store i32 %ext, i32 *%flag
78  ret i32 %val
79}
80
81declare {i32, i1} @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone
82
83