File: neg-abs.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (163 lines) | stat: -rw-r--r-- 4,580 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
; RUN:   | FileCheck %s --check-prefix=RV32I
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt -verify-machineinstrs < %s \
; RUN:   | FileCheck %s --check-prefix=RV32IBT
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
; RUN:   | FileCheck %s --check-prefix=RV64I
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbt -verify-machineinstrs < %s \
; RUN:   | FileCheck %s --check-prefix=RV64IBT

declare i32 @llvm.abs.i32(i32, i1 immarg)
declare i64 @llvm.abs.i64(i64, i1 immarg)

define i32 @neg_abs32(i32 %x) {
; RV32I-LABEL: neg_abs32:
; RV32I:       # %bb.0:
; RV32I-NEXT:    srai a1, a0, 31
; RV32I-NEXT:    xor a0, a0, a1
; RV32I-NEXT:    sub a0, a1, a0
; RV32I-NEXT:    ret
;
; RV32IBT-LABEL: neg_abs32:
; RV32IBT:       # %bb.0:
; RV32IBT-NEXT:    srai a1, a0, 31
; RV32IBT-NEXT:    xor a0, a0, a1
; RV32IBT-NEXT:    sub a0, a1, a0
; RV32IBT-NEXT:    ret
;
; RV64I-LABEL: neg_abs32:
; RV64I:       # %bb.0:
; RV64I-NEXT:    sraiw a1, a0, 31
; RV64I-NEXT:    xor a0, a0, a1
; RV64I-NEXT:    subw a0, a1, a0
; RV64I-NEXT:    ret
;
; RV64IBT-LABEL: neg_abs32:
; RV64IBT:       # %bb.0:
; RV64IBT-NEXT:    sraiw a1, a0, 31
; RV64IBT-NEXT:    xor a0, a0, a1
; RV64IBT-NEXT:    subw a0, a1, a0
; RV64IBT-NEXT:    ret
  %abs = tail call i32 @llvm.abs.i32(i32 %x, i1 true)
  %neg = sub nsw i32 0, %abs
  ret i32 %neg
}

define i32 @select_neg_abs32(i32 %x) {
; RV32I-LABEL: select_neg_abs32:
; RV32I:       # %bb.0:
; RV32I-NEXT:    srai a1, a0, 31
; RV32I-NEXT:    xor a0, a0, a1
; RV32I-NEXT:    sub a0, a1, a0
; RV32I-NEXT:    ret
;
; RV32IBT-LABEL: select_neg_abs32:
; RV32IBT:       # %bb.0:
; RV32IBT-NEXT:    srai a1, a0, 31
; RV32IBT-NEXT:    xor a0, a0, a1
; RV32IBT-NEXT:    sub a0, a1, a0
; RV32IBT-NEXT:    ret
;
; RV64I-LABEL: select_neg_abs32:
; RV64I:       # %bb.0:
; RV64I-NEXT:    sraiw a1, a0, 31
; RV64I-NEXT:    xor a0, a0, a1
; RV64I-NEXT:    subw a0, a1, a0
; RV64I-NEXT:    ret
;
; RV64IBT-LABEL: select_neg_abs32:
; RV64IBT:       # %bb.0:
; RV64IBT-NEXT:    sraiw a1, a0, 31
; RV64IBT-NEXT:    xor a0, a0, a1
; RV64IBT-NEXT:    subw a0, a1, a0
; RV64IBT-NEXT:    ret
  %1 = icmp slt i32 %x, 0
  %2 = sub nsw i32 0, %x
  %3 = select i1 %1, i32 %x, i32 %2
  ret i32 %3
}

define i64 @neg_abs64(i64 %x) {
; RV32I-LABEL: neg_abs64:
; RV32I:       # %bb.0:
; RV32I-NEXT:    srai a2, a1, 31
; RV32I-NEXT:    xor a0, a0, a2
; RV32I-NEXT:    sltu a3, a2, a0
; RV32I-NEXT:    xor a1, a1, a2
; RV32I-NEXT:    sub a1, a2, a1
; RV32I-NEXT:    sub a1, a1, a3
; RV32I-NEXT:    sub a0, a2, a0
; RV32I-NEXT:    ret
;
; RV32IBT-LABEL: neg_abs64:
; RV32IBT:       # %bb.0:
; RV32IBT-NEXT:    srai a2, a1, 31
; RV32IBT-NEXT:    xor a0, a0, a2
; RV32IBT-NEXT:    sltu a3, a2, a0
; RV32IBT-NEXT:    xor a1, a1, a2
; RV32IBT-NEXT:    sub a1, a2, a1
; RV32IBT-NEXT:    sub a1, a1, a3
; RV32IBT-NEXT:    sub a0, a2, a0
; RV32IBT-NEXT:    ret
;
; RV64I-LABEL: neg_abs64:
; RV64I:       # %bb.0:
; RV64I-NEXT:    srai a1, a0, 63
; RV64I-NEXT:    xor a0, a0, a1
; RV64I-NEXT:    sub a0, a1, a0
; RV64I-NEXT:    ret
;
; RV64IBT-LABEL: neg_abs64:
; RV64IBT:       # %bb.0:
; RV64IBT-NEXT:    srai a1, a0, 63
; RV64IBT-NEXT:    xor a0, a0, a1
; RV64IBT-NEXT:    sub a0, a1, a0
; RV64IBT-NEXT:    ret
  %abs = tail call i64 @llvm.abs.i64(i64 %x, i1 true)
  %neg = sub nsw i64 0, %abs
  ret i64 %neg
}

define i64 @select_neg_abs64(i64 %x) {
; RV32I-LABEL: select_neg_abs64:
; RV32I:       # %bb.0:
; RV32I-NEXT:    srai a2, a1, 31
; RV32I-NEXT:    xor a0, a0, a2
; RV32I-NEXT:    sltu a3, a2, a0
; RV32I-NEXT:    xor a1, a1, a2
; RV32I-NEXT:    sub a1, a2, a1
; RV32I-NEXT:    sub a1, a1, a3
; RV32I-NEXT:    sub a0, a2, a0
; RV32I-NEXT:    ret
;
; RV32IBT-LABEL: select_neg_abs64:
; RV32IBT:       # %bb.0:
; RV32IBT-NEXT:    srai a2, a1, 31
; RV32IBT-NEXT:    xor a0, a0, a2
; RV32IBT-NEXT:    sltu a3, a2, a0
; RV32IBT-NEXT:    xor a1, a1, a2
; RV32IBT-NEXT:    sub a1, a2, a1
; RV32IBT-NEXT:    sub a1, a1, a3
; RV32IBT-NEXT:    sub a0, a2, a0
; RV32IBT-NEXT:    ret
;
; RV64I-LABEL: select_neg_abs64:
; RV64I:       # %bb.0:
; RV64I-NEXT:    srai a1, a0, 63
; RV64I-NEXT:    xor a0, a0, a1
; RV64I-NEXT:    sub a0, a1, a0
; RV64I-NEXT:    ret
;
; RV64IBT-LABEL: select_neg_abs64:
; RV64IBT:       # %bb.0:
; RV64IBT-NEXT:    srai a1, a0, 63
; RV64IBT-NEXT:    xor a0, a0, a1
; RV64IBT-NEXT:    sub a0, a1, a0
; RV64IBT-NEXT:    ret
  %1 = icmp slt i64 %x, 0
  %2 = sub nsw i64 0, %x
  %3 = select i1 %1, i64 %x, i64 %2
  ret i64 %3
}