2017-01-07 06:58:02 +08:00
|
|
|
; RUN: opt < %s -instsimplify -S | FileCheck %s
|
|
|
|
|
2017-03-10 00:20:52 +08:00
|
|
|
; Division-by-zero is undef. UB in any vector lane means the whole op is undef.
|
2017-03-07 02:45:39 +08:00
|
|
|
|
2017-03-10 04:31:20 +08:00
|
|
|
define <2 x i8> @sdiv_zero_elt_vec_constfold(<2 x i8> %x) {
|
|
|
|
; CHECK-LABEL: @sdiv_zero_elt_vec_constfold(
|
2017-03-10 04:42:30 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i8> undef
|
2017-03-10 04:31:20 +08:00
|
|
|
;
|
|
|
|
%div = sdiv <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>
|
|
|
|
ret <2 x i8> %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i8> @udiv_zero_elt_vec_constfold(<2 x i8> %x) {
|
|
|
|
; CHECK-LABEL: @udiv_zero_elt_vec_constfold(
|
2017-03-10 04:42:30 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i8> undef
|
2017-03-10 04:31:20 +08:00
|
|
|
;
|
|
|
|
%div = udiv <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>
|
|
|
|
ret <2 x i8> %div
|
|
|
|
}
|
|
|
|
|
2017-03-07 02:45:39 +08:00
|
|
|
define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {
|
|
|
|
; CHECK-LABEL: @sdiv_zero_elt_vec(
|
2017-03-10 00:20:52 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i8> undef
|
2017-03-07 02:45:39 +08:00
|
|
|
;
|
|
|
|
%div = sdiv <2 x i8> %x, <i8 -42, i8 0>
|
|
|
|
ret <2 x i8> %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {
|
|
|
|
; CHECK-LABEL: @udiv_zero_elt_vec(
|
2017-03-10 00:20:52 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i8> undef
|
2017-03-07 02:45:39 +08:00
|
|
|
;
|
|
|
|
%div = udiv <2 x i8> %x, <i8 0, i8 42>
|
|
|
|
ret <2 x i8> %div
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:22:00 +08:00
|
|
|
define <2 x i8> @sdiv_undef_elt_vec(<2 x i8> %x) {
|
|
|
|
; CHECK-LABEL: @sdiv_undef_elt_vec(
|
|
|
|
; CHECK-NEXT: ret <2 x i8> undef
|
|
|
|
;
|
|
|
|
%div = sdiv <2 x i8> %x, <i8 -42, i8 undef>
|
|
|
|
ret <2 x i8> %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i8> @udiv_undef_elt_vec(<2 x i8> %x) {
|
|
|
|
; CHECK-LABEL: @udiv_undef_elt_vec(
|
|
|
|
; CHECK-NEXT: ret <2 x i8> undef
|
|
|
|
;
|
|
|
|
%div = udiv <2 x i8> %x, <i8 undef, i8 42>
|
|
|
|
ret <2 x i8> %div
|
|
|
|
}
|
|
|
|
|
2017-03-10 05:56:03 +08:00
|
|
|
; Division-by-zero is undef. UB in any vector lane means the whole op is undef.
|
2017-03-07 02:45:39 +08:00
|
|
|
; Thus, we can simplify this: if any element of 'y' is 0, we can do anything.
|
|
|
|
; Therefore, assume that all elements of 'y' must be 1.
|
|
|
|
|
|
|
|
define <2 x i1> @sdiv_bool_vec(<2 x i1> %x, <2 x i1> %y) {
|
|
|
|
; CHECK-LABEL: @sdiv_bool_vec(
|
2017-03-10 05:56:03 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i1> %x
|
2017-03-07 02:45:39 +08:00
|
|
|
;
|
|
|
|
%div = sdiv <2 x i1> %x, %y
|
|
|
|
ret <2 x i1> %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i1> @udiv_bool_vec(<2 x i1> %x, <2 x i1> %y) {
|
|
|
|
; CHECK-LABEL: @udiv_bool_vec(
|
2017-03-10 05:56:03 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i1> %x
|
2017-03-07 02:45:39 +08:00
|
|
|
;
|
|
|
|
%div = udiv <2 x i1> %x, %y
|
|
|
|
ret <2 x i1> %div
|
|
|
|
}
|
|
|
|
|
2017-09-12 04:38:31 +08:00
|
|
|
define i32 @udiv_dividend_known_smaller_than_constant_divisor(i32 %x) {
|
|
|
|
; CHECK-LABEL: @udiv_dividend_known_smaller_than_constant_divisor(
|
2017-09-11 01:55:08 +08:00
|
|
|
; CHECK-NEXT: ret i32 0
|
|
|
|
;
|
|
|
|
%and = and i32 %x, 250
|
|
|
|
%div = udiv i32 %and, 251
|
|
|
|
ret i32 %div
|
|
|
|
}
|
|
|
|
|
2017-09-12 04:38:31 +08:00
|
|
|
define i32 @not_udiv_dividend_known_smaller_than_constant_divisor(i32 %x) {
|
|
|
|
; CHECK-LABEL: @not_udiv_dividend_known_smaller_than_constant_divisor(
|
2017-09-11 01:55:08 +08:00
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 251
|
|
|
|
; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[AND]], 251
|
|
|
|
; CHECK-NEXT: ret i32 [[DIV]]
|
|
|
|
;
|
|
|
|
%and = and i32 %x, 251
|
|
|
|
%div = udiv i32 %and, 251
|
|
|
|
ret i32 %div
|
|
|
|
}
|
|
|
|
|
2017-09-12 04:38:31 +08:00
|
|
|
define i32 @udiv_constant_dividend_known_smaller_than_divisor(i32 %x) {
|
|
|
|
; CHECK-LABEL: @udiv_constant_dividend_known_smaller_than_divisor(
|
2017-09-11 01:55:08 +08:00
|
|
|
; CHECK-NEXT: ret i32 0
|
|
|
|
;
|
|
|
|
%or = or i32 %x, 251
|
|
|
|
%div = udiv i32 250, %or
|
|
|
|
ret i32 %div
|
|
|
|
}
|
|
|
|
|
2017-09-12 04:38:31 +08:00
|
|
|
define i32 @not_udiv_constant_dividend_known_smaller_than_divisor(i32 %x) {
|
|
|
|
; CHECK-LABEL: @not_udiv_constant_dividend_known_smaller_than_divisor(
|
2017-09-11 01:55:08 +08:00
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 251
|
|
|
|
; CHECK-NEXT: [[DIV:%.*]] = udiv i32 251, [[OR]]
|
|
|
|
; CHECK-NEXT: ret i32 [[DIV]]
|
|
|
|
;
|
|
|
|
%or = or i32 %x, 251
|
|
|
|
%div = udiv i32 251, %or
|
|
|
|
ret i32 %div
|
|
|
|
}
|
|
|
|
|
|
|
|
; This would require computing known bits on both x and y. Is it worth doing?
|
|
|
|
|
2017-09-12 04:38:31 +08:00
|
|
|
define i32 @udiv_dividend_known_smaller_than_divisor(i32 %x, i32 %y) {
|
|
|
|
; CHECK-LABEL: @udiv_dividend_known_smaller_than_divisor(
|
2017-09-11 01:55:08 +08:00
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 250
|
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or i32 %y, 251
|
|
|
|
; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[AND]], [[OR]]
|
|
|
|
; CHECK-NEXT: ret i32 [[DIV]]
|
|
|
|
;
|
|
|
|
%and = and i32 %x, 250
|
|
|
|
%or = or i32 %y, 251
|
|
|
|
%div = udiv i32 %and, %or
|
|
|
|
ret i32 %div
|
|
|
|
}
|
|
|
|
|
2017-09-12 04:38:31 +08:00
|
|
|
define i32 @not_udiv_dividend_known_smaller_than_divisor(i32 %x, i32 %y) {
|
|
|
|
; CHECK-LABEL: @not_udiv_dividend_known_smaller_than_divisor(
|
2017-09-11 01:55:08 +08:00
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 251
|
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or i32 %y, 251
|
|
|
|
; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[AND]], [[OR]]
|
|
|
|
; CHECK-NEXT: ret i32 [[DIV]]
|
|
|
|
;
|
|
|
|
%and = and i32 %x, 251
|
|
|
|
%or = or i32 %y, 251
|
|
|
|
%div = udiv i32 %and, %or
|
|
|
|
ret i32 %div
|
|
|
|
}
|
|
|
|
|
2017-01-07 06:58:02 +08:00
|
|
|
declare i32 @external()
|
|
|
|
|
|
|
|
define i32 @div1() {
|
|
|
|
; CHECK-LABEL: @div1(
|
2017-03-07 02:13:01 +08:00
|
|
|
; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), !range !0
|
2017-01-07 06:58:02 +08:00
|
|
|
; CHECK-NEXT: ret i32 0
|
|
|
|
;
|
|
|
|
%call = call i32 @external(), !range !0
|
|
|
|
%urem = udiv i32 %call, 3
|
|
|
|
ret i32 %urem
|
|
|
|
}
|
|
|
|
|
|
|
|
!0 = !{i32 0, i32 3}
|