blob: 3136f0242fa03b36aa44aa5be294623270a31379 [file] [log] [blame]
David Majnemer63da0c22017-01-06 22:58:02 +00001; RUN: opt < %s -instsimplify -S | FileCheck %s
2
Sanjay Patel3bbee792017-03-06 18:45:39 +00003; FIXME: Division-by-zero is undef. UB in any vector lane means the whole op is undef.
4
5define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {
6; CHECK-LABEL: @sdiv_zero_elt_vec(
7; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i8> %x, <i8 -42, i8 0>
8; CHECK-NEXT: ret <2 x i8> [[DIV]]
9;
10 %div = sdiv <2 x i8> %x, <i8 -42, i8 0>
11 ret <2 x i8> %div
12}
13
14define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {
15; CHECK-LABEL: @udiv_zero_elt_vec(
16; CHECK-NEXT: [[DIV:%.*]] = udiv <2 x i8> %x, <i8 0, i8 42>
17; CHECK-NEXT: ret <2 x i8> [[DIV]]
18;
19 %div = udiv <2 x i8> %x, <i8 0, i8 42>
20 ret <2 x i8> %div
21}
22
23; FIXME: Division-by-zero is undef. UB in any vector lane means the whole op is undef.
24; Thus, we can simplify this: if any element of 'y' is 0, we can do anything.
25; Therefore, assume that all elements of 'y' must be 1.
26
27define <2 x i1> @sdiv_bool_vec(<2 x i1> %x, <2 x i1> %y) {
28; CHECK-LABEL: @sdiv_bool_vec(
29; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i1> %x, %y
30; CHECK-NEXT: ret <2 x i1> [[DIV]]
31;
32 %div = sdiv <2 x i1> %x, %y
33 ret <2 x i1> %div
34}
35
36define <2 x i1> @udiv_bool_vec(<2 x i1> %x, <2 x i1> %y) {
37; CHECK-LABEL: @udiv_bool_vec(
38; CHECK-NEXT: [[DIV:%.*]] = udiv <2 x i1> %x, %y
39; CHECK-NEXT: ret <2 x i1> [[DIV]]
40;
41 %div = udiv <2 x i1> %x, %y
42 ret <2 x i1> %div
43}
44
David Majnemer63da0c22017-01-06 22:58:02 +000045declare i32 @external()
46
47define i32 @div1() {
48; CHECK-LABEL: @div1(
Sanjay Patelc4942392017-03-06 18:13:01 +000049; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), !range !0
David Majnemer63da0c22017-01-06 22:58:02 +000050; CHECK-NEXT: ret i32 0
51;
52 %call = call i32 @external(), !range !0
53 %urem = udiv i32 %call, 3
54 ret i32 %urem
55}
56
57!0 = !{i32 0, i32 3}