blob: f096719359dcde37c53aea74692e46734dd867ff [file] [log] [blame]
David Majnemer63da0c22017-01-06 22:58:02 +00001; RUN: opt < %s -instsimplify -S | FileCheck %s
2
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00003; Division-by-zero is undef. UB in any vector lane means the whole op is undef.
Sanjay Patel3bbee792017-03-06 18:45:39 +00004
Sanjay Patelbb476162017-03-09 20:31:20 +00005define <2 x i8> @sdiv_zero_elt_vec_constfold(<2 x i8> %x) {
6; CHECK-LABEL: @sdiv_zero_elt_vec_constfold(
Sanjay Patel7e563662017-03-09 20:42:30 +00007; CHECK-NEXT: ret <2 x i8> undef
Sanjay Patelbb476162017-03-09 20:31:20 +00008;
9 %div = sdiv <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>
10 ret <2 x i8> %div
11}
12
13define <2 x i8> @udiv_zero_elt_vec_constfold(<2 x i8> %x) {
14; CHECK-LABEL: @udiv_zero_elt_vec_constfold(
Sanjay Patel7e563662017-03-09 20:42:30 +000015; CHECK-NEXT: ret <2 x i8> undef
Sanjay Patelbb476162017-03-09 20:31:20 +000016;
17 %div = udiv <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>
18 ret <2 x i8> %div
19}
20
Sanjay Patel3bbee792017-03-06 18:45:39 +000021define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {
22; CHECK-LABEL: @sdiv_zero_elt_vec(
Sanjay Patel2b1f6f42017-03-09 16:20:52 +000023; CHECK-NEXT: ret <2 x i8> undef
Sanjay Patel3bbee792017-03-06 18:45:39 +000024;
25 %div = sdiv <2 x i8> %x, <i8 -42, i8 0>
26 ret <2 x i8> %div
27}
28
29define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {
30; CHECK-LABEL: @udiv_zero_elt_vec(
Sanjay Patel2b1f6f42017-03-09 16:20:52 +000031; CHECK-NEXT: ret <2 x i8> undef
Sanjay Patel3bbee792017-03-06 18:45:39 +000032;
33 %div = udiv <2 x i8> %x, <i8 0, i8 42>
34 ret <2 x i8> %div
35}
36
Sanjay Patel962a8432017-03-09 21:56:03 +000037; Division-by-zero is undef. UB in any vector lane means the whole op is undef.
Sanjay Patel3bbee792017-03-06 18:45:39 +000038; Thus, we can simplify this: if any element of 'y' is 0, we can do anything.
39; Therefore, assume that all elements of 'y' must be 1.
40
41define <2 x i1> @sdiv_bool_vec(<2 x i1> %x, <2 x i1> %y) {
42; CHECK-LABEL: @sdiv_bool_vec(
Sanjay Patel962a8432017-03-09 21:56:03 +000043; CHECK-NEXT: ret <2 x i1> %x
Sanjay Patel3bbee792017-03-06 18:45:39 +000044;
45 %div = sdiv <2 x i1> %x, %y
46 ret <2 x i1> %div
47}
48
49define <2 x i1> @udiv_bool_vec(<2 x i1> %x, <2 x i1> %y) {
50; CHECK-LABEL: @udiv_bool_vec(
Sanjay Patel962a8432017-03-09 21:56:03 +000051; CHECK-NEXT: ret <2 x i1> %x
Sanjay Patel3bbee792017-03-06 18:45:39 +000052;
53 %div = udiv <2 x i1> %x, %y
54 ret <2 x i1> %div
55}
56
David Majnemer63da0c22017-01-06 22:58:02 +000057declare i32 @external()
58
59define i32 @div1() {
60; CHECK-LABEL: @div1(
Sanjay Patelc4942392017-03-06 18:13:01 +000061; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), !range !0
David Majnemer63da0c22017-01-06 22:58:02 +000062; CHECK-NEXT: ret i32 0
63;
64 %call = call i32 @external(), !range !0
65 %urem = udiv i32 %call, 3
66 ret i32 %urem
67}
68
69!0 = !{i32 0, i32 3}