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