1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -global-isel -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s --check-prefix=RV32I
4 ; RUN: llc -mtriple=riscv32 -global-isel -mattr=+zbb -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s --check-prefix=RV32ZBB
6 ; RUN: llc -mtriple=riscv64 -global-isel -verify-machineinstrs < %s \
7 ; RUN: | FileCheck %s --check-prefix=RV64I
8 ; RUN: llc -mtriple=riscv64 -global-isel -mattr=+zbb -verify-machineinstrs < %s \
9 ; RUN: | FileCheck %s --check-prefix=RV64ZBB
11 declare i8 @llvm.abs.i8(i8, i1 immarg)
12 declare i16 @llvm.abs.i16(i16, i1 immarg)
13 declare i32 @llvm.abs.i32(i32, i1 immarg)
14 declare i64 @llvm.abs.i64(i64, i1 immarg)
16 define i8 @abs8(i8 %x) {
19 ; RV32I-NEXT: slli a1, a0, 24
20 ; RV32I-NEXT: srai a1, a1, 24
21 ; RV32I-NEXT: srai a1, a1, 7
22 ; RV32I-NEXT: add a0, a0, a1
23 ; RV32I-NEXT: xor a0, a0, a1
26 ; RV32ZBB-LABEL: abs8:
28 ; RV32ZBB-NEXT: slli a0, a0, 24
29 ; RV32ZBB-NEXT: srai a0, a0, 24
30 ; RV32ZBB-NEXT: neg a1, a0
31 ; RV32ZBB-NEXT: max a0, a0, a1
36 ; RV64I-NEXT: slli a1, a0, 24
37 ; RV64I-NEXT: sraiw a1, a1, 24
38 ; RV64I-NEXT: sraiw a1, a1, 7
39 ; RV64I-NEXT: addw a0, a0, a1
40 ; RV64I-NEXT: xor a0, a0, a1
43 ; RV64ZBB-LABEL: abs8:
45 ; RV64ZBB-NEXT: slli a0, a0, 56
46 ; RV64ZBB-NEXT: srai a0, a0, 56
47 ; RV64ZBB-NEXT: neg a1, a0
48 ; RV64ZBB-NEXT: max a0, a0, a1
50 %abs = tail call i8 @llvm.abs.i8(i8 %x, i1 true)
54 define i16 @abs16(i16 %x) {
57 ; RV32I-NEXT: slli a1, a0, 16
58 ; RV32I-NEXT: srai a1, a1, 16
59 ; RV32I-NEXT: srai a1, a1, 15
60 ; RV32I-NEXT: add a0, a0, a1
61 ; RV32I-NEXT: xor a0, a0, a1
64 ; RV32ZBB-LABEL: abs16:
66 ; RV32ZBB-NEXT: slli a0, a0, 16
67 ; RV32ZBB-NEXT: srai a0, a0, 16
68 ; RV32ZBB-NEXT: neg a1, a0
69 ; RV32ZBB-NEXT: max a0, a0, a1
74 ; RV64I-NEXT: slli a1, a0, 16
75 ; RV64I-NEXT: sraiw a1, a1, 16
76 ; RV64I-NEXT: sraiw a1, a1, 15
77 ; RV64I-NEXT: addw a0, a0, a1
78 ; RV64I-NEXT: xor a0, a0, a1
81 ; RV64ZBB-LABEL: abs16:
83 ; RV64ZBB-NEXT: slli a0, a0, 48
84 ; RV64ZBB-NEXT: srai a0, a0, 48
85 ; RV64ZBB-NEXT: neg a1, a0
86 ; RV64ZBB-NEXT: max a0, a0, a1
88 %abs = tail call i16 @llvm.abs.i16(i16 %x, i1 true)
92 define i32 @abs32(i32 %x) {
95 ; RV32I-NEXT: srai a1, a0, 31
96 ; RV32I-NEXT: add a0, a0, a1
97 ; RV32I-NEXT: xor a0, a0, a1
100 ; RV32ZBB-LABEL: abs32:
102 ; RV32ZBB-NEXT: neg a1, a0
103 ; RV32ZBB-NEXT: max a0, a0, a1
106 ; RV64I-LABEL: abs32:
108 ; RV64I-NEXT: sraiw a1, a0, 31
109 ; RV64I-NEXT: addw a0, a0, a1
110 ; RV64I-NEXT: xor a0, a0, a1
113 ; RV64ZBB-LABEL: abs32:
115 ; RV64ZBB-NEXT: negw a1, a0
116 ; RV64ZBB-NEXT: sext.w a0, a0
117 ; RV64ZBB-NEXT: max a0, a0, a1
119 %abs = tail call i32 @llvm.abs.i32(i32 %x, i1 true)
123 define i64 @abs64(i64 %x) {
124 ; RV32I-LABEL: abs64:
126 ; RV32I-NEXT: srai a2, a1, 31
127 ; RV32I-NEXT: add a0, a0, a2
128 ; RV32I-NEXT: sltu a3, a0, a2
129 ; RV32I-NEXT: add a1, a1, a2
130 ; RV32I-NEXT: add a1, a1, a3
131 ; RV32I-NEXT: xor a0, a0, a2
132 ; RV32I-NEXT: xor a1, a1, a2
135 ; RV32ZBB-LABEL: abs64:
137 ; RV32ZBB-NEXT: srai a2, a1, 31
138 ; RV32ZBB-NEXT: add a0, a0, a2
139 ; RV32ZBB-NEXT: sltu a3, a0, a2
140 ; RV32ZBB-NEXT: add a1, a1, a2
141 ; RV32ZBB-NEXT: add a1, a1, a3
142 ; RV32ZBB-NEXT: xor a0, a0, a2
143 ; RV32ZBB-NEXT: xor a1, a1, a2
146 ; RV64I-LABEL: abs64:
148 ; RV64I-NEXT: srai a1, a0, 63
149 ; RV64I-NEXT: add a0, a0, a1
150 ; RV64I-NEXT: xor a0, a0, a1
153 ; RV64ZBB-LABEL: abs64:
155 ; RV64ZBB-NEXT: neg a1, a0
156 ; RV64ZBB-NEXT: max a0, a0, a1
158 %abs = tail call i64 @llvm.abs.i64(i64 %x, i1 true)