1 ; Test integer absolute.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5 ; Test i32->i32 absolute using slt.
6 define i32 @f1(i32 %val) {
10 %cmp = icmp slt i32 %val, 0
11 %neg = sub i32 0, %val
12 %res = select i1 %cmp, i32 %neg, i32 %val
16 ; Test i32->i32 absolute using sle.
17 define i32 @f2(i32 %val) {
21 %cmp = icmp sle i32 %val, 0
22 %neg = sub i32 0, %val
23 %res = select i1 %cmp, i32 %neg, i32 %val
27 ; Test i32->i32 absolute using sgt.
28 define i32 @f3(i32 %val) {
32 %cmp = icmp sgt i32 %val, 0
33 %neg = sub i32 0, %val
34 %res = select i1 %cmp, i32 %val, i32 %neg
38 ; Test i32->i32 absolute using sge.
39 define i32 @f4(i32 %val) {
43 %cmp = icmp sge i32 %val, 0
44 %neg = sub i32 0, %val
45 %res = select i1 %cmp, i32 %val, i32 %neg
49 ; Test i32->i64 absolute.
50 define i64 @f5(i32 %val) {
52 ; CHECK: lpgfr %r2, %r2
54 %ext = sext i32 %val to i64
55 %cmp = icmp slt i64 %ext, 0
56 %neg = sub i64 0, %ext
57 %res = select i1 %cmp, i64 %neg, i64 %ext
61 ; Test i32->i64 absolute that uses an "in-register" form of sign extension.
62 define i64 @f6(i64 %val) {
64 ; CHECK: lpgfr %r2, %r2
66 %trunc = trunc i64 %val to i32
67 %ext = sext i32 %trunc to i64
68 %cmp = icmp slt i64 %ext, 0
69 %neg = sub i64 0, %ext
70 %res = select i1 %cmp, i64 %neg, i64 %ext
75 define i64 @f7(i64 %val) {
77 ; CHECK: lpgr %r2, %r2
79 %cmp = icmp slt i64 %val, 0
80 %neg = sub i64 0, %val
81 %res = select i1 %cmp, i64 %neg, i64 %val
85 ; Test another form of f6, which is that produced by InstCombine.
86 define i64 @f8(i64 %val) {
88 ; CHECK: lpgfr %r2, %r2
90 %shl = shl i64 %val, 32
91 %ashr = ashr i64 %shl, 32
92 %neg = sub i64 0, %ashr
93 %cmp = icmp slt i64 %shl, 0
94 %abs = select i1 %cmp, i64 %neg, i64 %ashr
98 ; Try again with sle rather than slt.
99 define i64 @f9(i64 %val) {
101 ; CHECK: lpgfr %r2, %r2
103 %shl = shl i64 %val, 32
104 %ashr = ashr i64 %shl, 32
105 %neg = sub i64 0, %ashr
106 %cmp = icmp sle i64 %shl, 0
107 %abs = select i1 %cmp, i64 %neg, i64 %ashr
111 ; Repeat f8 with the operands reversed.
112 define i64 @f10(i64 %val) {
114 ; CHECK: lpgfr %r2, %r2
116 %shl = shl i64 %val, 32
117 %ashr = ashr i64 %shl, 32
118 %neg = sub i64 0, %ashr
119 %cmp = icmp sgt i64 %shl, 0
120 %abs = select i1 %cmp, i64 %ashr, i64 %neg
124 ; Try again with sge rather than sgt.
125 define i64 @f11(i64 %val) {
127 ; CHECK: lpgfr %r2, %r2
129 %shl = shl i64 %val, 32
130 %ashr = ashr i64 %shl, 32
131 %neg = sub i64 0, %ashr
132 %cmp = icmp sge i64 %shl, 0
133 %abs = select i1 %cmp, i64 %ashr, i64 %neg
137 ; Repeat f5 with the comparison on the unextended value.
138 define i64 @f12(i32 %val) {
140 ; CHECK: lpgfr %r2, %r2
142 %ext = sext i32 %val to i64
143 %cmp = icmp slt i32 %val, 0
144 %neg = sub i64 0, %ext
145 %abs = select i1 %cmp, i64 %neg, i64 %ext