Skip to content

Commit 786df0c

Browse files
committed
ValueTracking/test: cover known bits of mul
1 parent 9d5cecc commit 786df0c

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3+
4+
define i8 @mul_low_bits_know(i8 %xx, i8 %yy) {
5+
; CHECK-LABEL: define i8 @mul_low_bits_know(
6+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
7+
; CHECK-NEXT: ret i8 0
8+
;
9+
%x = and i8 %xx, 2
10+
%y = and i8 %yy, 4
11+
%mul = mul i8 %x, %y
12+
%r = and i8 %mul, 6
13+
ret i8 %r
14+
}
15+
16+
define i8 @mul_low_bits_know2(i8 %xx, i8 %yy) {
17+
; CHECK-LABEL: define i8 @mul_low_bits_know2(
18+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
19+
; CHECK-NEXT: ret i8 0
20+
;
21+
%x = or i8 %xx, -2
22+
%y = and i8 %yy, 4
23+
%mul = mul i8 %x, %y
24+
%r = and i8 %mul, 2
25+
ret i8 %r
26+
}
27+
28+
define i8 @mul_low_bits_partially_known(i8 %xx, i8 %yy) {
29+
; CHECK-LABEL: define i8 @mul_low_bits_partially_known(
30+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
31+
; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY]], 2
32+
; CHECK-NEXT: [[MUL:%.*]] = sub nsw i8 0, [[Y]]
33+
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], 2
34+
; CHECK-NEXT: ret i8 [[R]]
35+
;
36+
%x = or i8 %xx, -4
37+
%x.notsmin = or i8 %x, 3
38+
%y = or i8 %yy, -2
39+
%mul = mul i8 %x.notsmin, %y
40+
%r = and i8 %mul, 6
41+
ret i8 %r
42+
}
43+
44+
define i8 @mul_low_bits_unknown(i8 %xx, i8 %yy) {
45+
; CHECK-LABEL: define i8 @mul_low_bits_unknown(
46+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
47+
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX]], 4
48+
; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY]], 6
49+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
50+
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], 6
51+
; CHECK-NEXT: ret i8 [[R]]
52+
;
53+
%x = or i8 %xx, -4
54+
%y = or i8 %yy, -2
55+
%mul = mul i8 %x, %y
56+
%r = and i8 %mul, 6
57+
ret i8 %r
58+
}
59+
60+
define i8 @mul_high_bits_know(i8 %xx, i8 %yy) {
61+
; CHECK-LABEL: define i8 @mul_high_bits_know(
62+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
63+
; CHECK-NEXT: ret i8 0
64+
;
65+
%x = and i8 %xx, 2
66+
%y = and i8 %yy, 4
67+
%mul = mul i8 %x, %y
68+
%r = and i8 %mul, 16
69+
ret i8 %r
70+
}
71+
72+
define i8 @mul_high_bits_know2(i8 %xx, i8 %yy) {
73+
; CHECK-LABEL: define i8 @mul_high_bits_know2(
74+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
75+
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX]], -2
76+
; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY]], 4
77+
; CHECK-NEXT: [[Y_NONZERO:%.*]] = or disjoint i8 [[Y]], 1
78+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y_NONZERO]]
79+
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], -16
80+
; CHECK-NEXT: ret i8 [[R]]
81+
;
82+
%x = or i8 %xx, -2
83+
%y = and i8 %yy, 4
84+
%y.nonzero = or i8 %y, 1
85+
%mul = mul i8 %x, %y.nonzero
86+
%r = and i8 %mul, -16
87+
ret i8 %r
88+
}
89+
90+
define i8 @mul_high_bits_know3(i8 %xx, i8 %yy) {
91+
; CHECK-LABEL: define i8 @mul_high_bits_know3(
92+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
93+
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX]], 124
94+
; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY]], 126
95+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
96+
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], 112
97+
; CHECK-NEXT: ret i8 [[R]]
98+
;
99+
%x = or i8 %xx, -4
100+
%y = or i8 %yy, -2
101+
%mul = mul i8 %x, %y
102+
%r = and i8 %mul, -16
103+
ret i8 %r
104+
}
105+
106+
define i8 @mul_high_bits_unknown(i8 %xx, i8 %yy) {
107+
; CHECK-LABEL: define i8 @mul_high_bits_unknown(
108+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
109+
; CHECK-NEXT: [[X:%.*]] = and i8 [[XX]], 2
110+
; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY]], 4
111+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i8 [[X]], [[Y]]
112+
; CHECK-NEXT: ret i8 [[MUL]]
113+
;
114+
%x = and i8 %xx, 2
115+
%y = and i8 %yy, 4
116+
%mul = mul i8 %x, %y
117+
%r = and i8 %mul, 8
118+
ret i8 %r
119+
}
120+
121+
define i8 @mul_high_bits_unknown2(i8 %xx, i8 %yy) {
122+
; CHECK-LABEL: define i8 @mul_high_bits_unknown2(
123+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
124+
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX]], -2
125+
; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY]], 4
126+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y]]
127+
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], -16
128+
; CHECK-NEXT: ret i8 [[R]]
129+
;
130+
%x = or i8 %xx, -2
131+
%y = and i8 %yy, 4
132+
%mul = mul i8 %x, %y
133+
%r = and i8 %mul, -16
134+
ret i8 %r
135+
}
136+
137+
; TODO: This can be reduced to zero.
138+
define i8 @mul_high_bits_unknown3(i8 %xx, i8 %yy) {
139+
; CHECK-LABEL: define i8 @mul_high_bits_unknown3(
140+
; CHECK-SAME: i8 [[XX:%.*]], i8 [[YY:%.*]]) {
141+
; CHECK-NEXT: [[X:%.*]] = or i8 [[XX]], 28
142+
; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY]], 30
143+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
144+
; CHECK-NEXT: [[R:%.*]] = and i8 [[MUL]], 16
145+
; CHECK-NEXT: ret i8 [[R]]
146+
;
147+
%x = or i8 %xx, -4
148+
%y = or i8 %yy, -2
149+
%mul = mul i8 %x, %y
150+
%r = and i8 %mul, 16
151+
ret i8 %r
152+
}

0 commit comments

Comments
 (0)