Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit acccef0

Browse files
committed
[InstCombine] consolidate rem tests and update checks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297747 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 68e70a5 commit acccef0

File tree

5 files changed

+143
-138
lines changed

5 files changed

+143
-138
lines changed

test/Transforms/InstCombine/2008-11-20-DivMulRem.ll

Lines changed: 0 additions & 67 deletions
This file was deleted.

test/Transforms/InstCombine/rem.ll

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,147 @@
11
; RUN: opt < %s -instcombine -S | FileCheck %s
22

3+
define i64 @rem_signed(i64 %x1, i64 %y2) {
4+
; CHECK-LABEL: @rem_signed(
5+
; CHECK-NEXT: [[R:%.*]] = srem i64 %x1, %y2
6+
; CHECK-NEXT: ret i64 [[R]]
7+
;
8+
%r = sdiv i64 %x1, %y2
9+
%r7 = mul i64 %r, %y2
10+
%r8 = sub i64 %x1, %r7
11+
ret i64 %r8
12+
}
13+
14+
define <4 x i32> @rem_signed_vec(<4 x i32> %t, <4 x i32> %u) {
15+
; CHECK-LABEL: @rem_signed_vec(
16+
; CHECK-NEXT: [[K:%.*]] = srem <4 x i32> %t, %u
17+
; CHECK-NEXT: ret <4 x i32> [[K]]
18+
;
19+
%k = sdiv <4 x i32> %t, %u
20+
%l = mul <4 x i32> %k, %u
21+
%m = sub <4 x i32> %t, %l
22+
ret <4 x i32> %m
23+
}
24+
25+
define i64 @rem_unsigned(i64 %x1, i64 %y2) {
26+
; CHECK-LABEL: @rem_unsigned(
27+
; CHECK-NEXT: [[R:%.*]] = urem i64 %x1, %y2
28+
; CHECK-NEXT: ret i64 [[R]]
29+
;
30+
%r = udiv i64 %x1, %y2
31+
%r7 = mul i64 %r, %y2
32+
%r8 = sub i64 %x1, %r7
33+
ret i64 %r8
34+
}
35+
36+
; PR28672 - https://llvm.org/bugs/show_bug.cgi?id=28672
37+
38+
define i8 @big_divisor(i8 %x) {
39+
; CHECK-LABEL: @big_divisor(
40+
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 %x, -127
41+
; CHECK-NEXT: [[TMP2:%.*]] = add i8 %x, 127
42+
; CHECK-NEXT: [[REM:%.*]] = select i1 [[TMP1]], i8 %x, i8 [[TMP2]]
43+
; CHECK-NEXT: ret i8 [[REM]]
44+
;
45+
%rem = urem i8 %x, 129
46+
ret i8 %rem
47+
}
48+
49+
define i5 @biggest_divisor(i5 %x) {
50+
; CHECK-LABEL: @biggest_divisor(
51+
; CHECK-NEXT: [[NOT_:%.*]] = icmp eq i5 %x, -1
52+
; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[NOT_]] to i5
53+
; CHECK-NEXT: [[REM:%.*]] = add i5 [[TMP1]], %x
54+
; CHECK-NEXT: ret i5 [[REM]]
55+
;
56+
%rem = urem i5 %x, -1
57+
ret i5 %rem
58+
}
59+
60+
; TODO: Should vector subtract of constant be canonicalized to add?
61+
define <2 x i4> @big_divisor_vec(<2 x i4> %x) {
62+
; CHECK-LABEL: @big_divisor_vec(
63+
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <2 x i4> %x, <i4 -3, i4 -3>
64+
; CHECK-NEXT: [[TMP2:%.*]] = sub <2 x i4> %x, <i4 -3, i4 -3>
65+
; CHECK-NEXT: [[REM:%.*]] = select <2 x i1> [[TMP1]], <2 x i4> %x, <2 x i4> [[TMP2]]
66+
; CHECK-NEXT: ret <2 x i4> [[REM]]
67+
;
68+
%rem = urem <2 x i4> %x, <i4 13, i4 13>
69+
ret <2 x i4> %rem
70+
}
71+
72+
define i8 @urem1(i8 %x, i8 %y) {
73+
; CHECK-LABEL: @urem1(
74+
; CHECK-NEXT: [[A:%.*]] = urem i8 %x, %y
75+
; CHECK-NEXT: ret i8 [[A]]
76+
;
77+
%A = udiv i8 %x, %y
78+
%B = mul i8 %A, %y
79+
%C = sub i8 %x, %B
80+
ret i8 %C
81+
}
82+
83+
define i8 @srem1(i8 %x, i8 %y) {
84+
; CHECK-LABEL: @srem1(
85+
; CHECK-NEXT: [[A:%.*]] = srem i8 %x, %y
86+
; CHECK-NEXT: ret i8 [[A]]
87+
;
88+
%A = sdiv i8 %x, %y
89+
%B = mul i8 %A, %y
90+
%C = sub i8 %x, %B
91+
ret i8 %C
92+
}
93+
94+
define i8 @urem2(i8 %x, i8 %y) {
95+
; CHECK-LABEL: @urem2(
96+
; CHECK-NEXT: [[A:%.*]] = urem i8 %x, %y
97+
; CHECK-NEXT: [[C:%.*]] = sub i8 0, [[A]]
98+
; CHECK-NEXT: ret i8 [[C]]
99+
;
100+
%A = udiv i8 %x, %y
101+
%B = mul i8 %A, %y
102+
%C = sub i8 %B, %x
103+
ret i8 %C
104+
}
105+
106+
define i8 @urem3(i8 %x) {
107+
; CHECK-LABEL: @urem3(
108+
; CHECK-NEXT: [[A:%.*]] = urem i8 %x, 3
109+
; CHECK-NEXT: [[B1:%.*]] = sub i8 %x, [[A]]
110+
; CHECK-NEXT: [[C:%.*]] = add i8 [[B1]], %x
111+
; CHECK-NEXT: ret i8 [[C]]
112+
;
113+
%A = udiv i8 %x, 3
114+
%B = mul i8 %A, -3
115+
%C = sub i8 %x, %B
116+
ret i8 %C
117+
}
118+
119+
; (((X / Y) * Y) / Y) -> X / Y
120+
121+
define i32 @sdiv_mul_sdiv(i32 %x, i32 %y) {
122+
; CHECK-LABEL: @sdiv_mul_sdiv(
123+
; CHECK-NEXT: [[R:%.*]] = sdiv i32 %x, %y
124+
; CHECK-NEXT: ret i32 [[R]]
125+
;
126+
%div = sdiv i32 %x, %y
127+
%mul = mul i32 %div, %y
128+
%r = sdiv i32 %mul, %y
129+
ret i32 %r
130+
}
131+
132+
; (((X / Y) * Y) / Y) -> X / Y
133+
134+
define i32 @udiv_mul_udiv(i32 %x, i32 %y) {
135+
; CHECK-LABEL: @udiv_mul_udiv(
136+
; CHECK-NEXT: [[R:%.*]] = udiv i32 %x, %y
137+
; CHECK-NEXT: ret i32 [[R]]
138+
;
139+
%div = udiv i32 %x, %y
140+
%mul = mul i32 %div, %y
141+
%r = udiv i32 %mul, %y
142+
ret i32 %r
143+
}
144+
3145
define i32 @test1(i32 %A) {
4146
; CHECK-LABEL: @test1(
5147
; CHECK-NEXT: ret i32 0
@@ -429,3 +571,4 @@ rem.is.safe:
429571
rem.is.unsafe:
430572
ret i32 0
431573
}
574+

test/Transforms/InstCombine/srem.ll

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/Transforms/InstCombine/urem.ll

Lines changed: 0 additions & 50 deletions
This file was deleted.

test/Transforms/InstCombine/vector-srem.ll

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)