Skip to content

Commit 880fc1c

Browse files
artagnonSterling-Augustine
authored andcommitted
ValueTracking/test: cover known-high-bits of rem (llvm#109006)
There is an underlying bug in KnownBits, and we should theoretically be able to determine the high-bits of an srem as shown in the test, just like urem. In preparation to fix this bug, add pre-commit tests testing high-bits of srem and urem.
1 parent 50211f4 commit 880fc1c

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

llvm/test/Analysis/ValueTracking/knownbits-rem-lowbits.ll renamed to llvm/test/Analysis/ValueTracking/knownbits-rem.ll

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ define i8 @urem_low_bits_know(i8 %xx, i8 %yy) {
1212
ret i8 %r
1313
}
1414

15+
define i8 @urem_high_bits_know(i8 %xx, i8 %yy) {
16+
; CHECK-LABEL: @urem_high_bits_know(
17+
; CHECK-NEXT: ret i8 0
18+
;
19+
%x = and i8 %xx, 2
20+
%y = and i8 %yy, -4
21+
%rem = urem i8 %x, %y
22+
%r = and i8 %rem, 8
23+
ret i8 %r
24+
}
25+
1526
define i8 @urem_low_bits_know2(i8 %xx, i8 %yy) {
1627
; CHECK-LABEL: @urem_low_bits_know2(
1728
; CHECK-NEXT: ret i8 2
@@ -91,6 +102,74 @@ define i8 @srem_low_bits_know2(i8 %xx, i8 %yy) {
91102
ret i8 %r
92103
}
93104

105+
define i8 @srem_high_bits_know(i8 %xx, i8 %yy) {
106+
; CHECK-LABEL: @srem_high_bits_know(
107+
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], -2
108+
; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY:%.*]], -4
109+
; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
110+
; CHECK-NEXT: [[R:%.*]] = and i8 [[REM]], -2
111+
; CHECK-NEXT: ret i8 [[R]]
112+
;
113+
%x = or i8 %xx, -2
114+
%y = and i8 %yy, -4
115+
%rem = srem i8 %x, %y
116+
%r = and i8 %rem, -2
117+
ret i8 %r
118+
}
119+
120+
define i8 @srem_high_bits_know2(i8 %xx, i8 %yy) {
121+
; CHECK-LABEL: @srem_high_bits_know2(
122+
; CHECK-NEXT: [[X:%.*]] = and i8 [[XX:%.*]], 13
123+
; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY:%.*]], -4
124+
; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
125+
; CHECK-NEXT: [[R:%.*]] = and i8 [[REM]], 8
126+
; CHECK-NEXT: ret i8 [[R]]
127+
;
128+
%x = and i8 %xx, 13
129+
%y = or i8 %yy, -4
130+
%rem = srem i8 %x, %y
131+
%r = and i8 %rem, 8
132+
ret i8 %r
133+
}
134+
135+
define i8 @srem_high_bits_know3(i8 %xx, i8 %yy) {
136+
; CHECK-LABEL: @srem_high_bits_know3(
137+
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], -13
138+
; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY:%.*]], 4
139+
; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
140+
; CHECK-NEXT: [[R:%.*]] = and i8 [[REM]], 8
141+
; CHECK-NEXT: ret i8 [[R]]
142+
;
143+
%x = or i8 %xx, -13
144+
%y = and i8 %yy, 4
145+
%rem = srem i8 %x, %y
146+
%r = and i8 %rem, 8
147+
ret i8 %r
148+
}
149+
150+
define i8 @srem_high_bits_know4(i8 %xx, i8 %yy) {
151+
; CHECK-LABEL: @srem_high_bits_know4(
152+
; CHECK-NEXT: ret i8 0
153+
;
154+
%x = and i8 %xx, 4
155+
%y = or i8 %yy, -13
156+
%rem = srem i8 %x, %y
157+
%r = and i8 %rem, 8
158+
ret i8 %r
159+
}
160+
161+
define i8 @srem_high_bits_know5(i8 %xx, i8 %yy) {
162+
; CHECK-LABEL: @srem_high_bits_know5(
163+
; CHECK-NEXT: [[X:%.*]] = and i8 [[XX:%.*]], 2
164+
; CHECK-NEXT: ret i8 [[X]]
165+
;
166+
%x = and i8 %xx, 2
167+
%y = and i8 %yy, 4
168+
%rem = srem i8 %x, %y
169+
%r = and i8 %rem, 2
170+
ret i8 %r
171+
}
172+
94173
define i8 @srem_todo_low_bits_partially_know_should_fold_out_srem(i8 %xx, i8 %yy) {
95174
; CHECK-LABEL: @srem_todo_low_bits_partially_know_should_fold_out_srem(
96175
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], 10

0 commit comments

Comments
 (0)