summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-04-09 13:41:29 +0000
committerSanjay Patel <spatel@rotateright.com>2019-04-09 13:41:29 +0000
commita230bb5fc04c8a80cd66568e543c55985dfc3007 (patch)
tree31ac0aa19ac6746e0138078cd319c37b24662afa
parent32b65345c5760295d04c95e0abb3653fe20ffd16 (diff)
downloadbcm5719-llvm-a230bb5fc04c8a80cd66568e543c55985dfc3007.tar.gz
bcm5719-llvm-a230bb5fc04c8a80cd66568e543c55985dfc3007.zip
[InstCombine] add tests/comments for negate+sdiv; NFC
llvm-svn: 358003
-rw-r--r--llvm/test/Transforms/InstCombine/div.ll35
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/div.ll b/llvm/test/Transforms/InstCombine/div.ll
index e1250179d27..00d4bd7ce28 100644
--- a/llvm/test/Transforms/InstCombine/div.ll
+++ b/llvm/test/Transforms/InstCombine/div.ll
@@ -780,6 +780,20 @@ define <2 x i64> @test_exact_vec(<2 x i64> %x) {
ret <2 x i64> %neg
}
+; Constant is safe to negate.
+
+define <2 x i8> @negate_sdiv_vec_splat(<2 x i8> %x) {
+; CHECK-LABEL: @negate_sdiv_vec_splat(
+; CHECK-NEXT: [[NEG:%.*]] = sdiv <2 x i8> [[X:%.*]], <i8 -42, i8 -42>
+; CHECK-NEXT: ret <2 x i8> [[NEG]]
+;
+ %div = sdiv <2 x i8> %x, <i8 42, i8 42>
+ %neg = sub <2 x i8> zeroinitializer, %div
+ ret <2 x i8> %neg
+}
+
+; Dividing by undef is UB.
+
define <2 x i8> @negate_sdiv_vec_undef_elt(<2 x i8> %x) {
; CHECK-LABEL: @negate_sdiv_vec_undef_elt(
; CHECK-NEXT: ret <2 x i8> undef
@@ -789,6 +803,8 @@ define <2 x i8> @negate_sdiv_vec_undef_elt(<2 x i8> %x) {
ret <2 x i8> %neg
}
+; Division by -1 may be UB (if numerator is the signed min val), but div-by-1 can be simplified.
+
define <2 x i8> @negate_sdiv_vec_splat_one(<2 x i8> %x) {
; CHECK-LABEL: @negate_sdiv_vec_splat_one(
; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
@@ -799,6 +815,8 @@ define <2 x i8> @negate_sdiv_vec_splat_one(<2 x i8> %x) {
ret <2 x i8> %neg
}
+; Can't negate signed-min constant, but can convert to a compare..
+
define <2 x i8> @negate_sdiv_vec_splat_signed_min(<2 x i8> %x) {
; CHECK-LABEL: @negate_sdiv_vec_splat_signed_min(
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 -128, i8 -128>
@@ -810,6 +828,8 @@ define <2 x i8> @negate_sdiv_vec_splat_signed_min(<2 x i8> %x) {
ret <2 x i8> %neg
}
+; Division by -1 may be UB for any element of a vector.
+
define <2 x i8> @negate_sdiv_vec_one_element(<2 x i8> %x) {
; CHECK-LABEL: @negate_sdiv_vec_one_element(
; CHECK-NEXT: [[NEG:%.*]] = sdiv <2 x i8> [[X:%.*]], <i8 1, i8 -1>
@@ -820,6 +840,8 @@ define <2 x i8> @negate_sdiv_vec_one_element(<2 x i8> %x) {
ret <2 x i8> %neg
}
+; Division by -1 may be UB and can't negate signed-min.
+
define <2 x i8> @negate_sdiv_vec_signed_min_elt(<2 x i8> %x) {
; CHECK-LABEL: @negate_sdiv_vec_signed_min_elt(
; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i8> [[X:%.*]], <i8 -1, i8 -128>
@@ -831,6 +853,19 @@ define <2 x i8> @negate_sdiv_vec_signed_min_elt(<2 x i8> %x) {
ret <2 x i8> %neg
}
+; Can't negate signed-min constant for any element of a vector.
+
+define <2 x i8> @negate_sdiv_vec_signed_min_and_one_elt(<2 x i8> %x) {
+; CHECK-LABEL: @negate_sdiv_vec_signed_min_and_one_elt(
+; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i8> [[X:%.*]], <i8 1, i8 -128>
+; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[DIV]]
+; CHECK-NEXT: ret <2 x i8> [[NEG]]
+;
+ %div = sdiv <2 x i8> %x, <i8 1, i8 -128>
+ %neg = sub <2 x i8> zeroinitializer, %div
+ ret <2 x i8> %neg
+}
+
define i32 @test_exact_nonsw_exact(i32 %x) {
; CHECK-LABEL: @test_exact_nonsw_exact(
; CHECK-NEXT: [[NEG:%.*]] = sdiv exact i32 [[X:%.*]], -3
OpenPOWER on IntegriCloud