OSDN Git Service

[InstSimplify] add tests for vector div/rem with UB potential; NFC
authorSanjay Patel <spatel@rotateright.com>
Mon, 6 Mar 2017 18:45:39 +0000 (18:45 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 6 Mar 2017 18:45:39 +0000 (18:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297048 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/InstSimplify/div.ll
test/Transforms/InstSimplify/rem.ll

index cad2a0d..3136f02 100644 (file)
@@ -1,5 +1,47 @@
 ; RUN: opt < %s -instsimplify -S | FileCheck %s
 
+; FIXME: Division-by-zero is undef. UB in any vector lane means the whole op is undef.
+
+define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {
+; CHECK-LABEL: @sdiv_zero_elt_vec(
+; CHECK-NEXT:    [[DIV:%.*]] = sdiv <2 x i8> %x, <i8 -42, i8 0>
+; CHECK-NEXT:    ret <2 x i8> [[DIV]]
+;
+  %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(
+; CHECK-NEXT:    [[DIV:%.*]] = udiv <2 x i8> %x, <i8 0, i8 42>
+; CHECK-NEXT:    ret <2 x i8> [[DIV]]
+;
+  %div = udiv <2 x i8> %x, <i8 0, i8 42>
+  ret <2 x i8> %div
+}
+
+; FIXME: Division-by-zero is undef. UB in any vector lane means the whole op is undef.
+; 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(
+; CHECK-NEXT:    [[DIV:%.*]] = sdiv <2 x i1> %x, %y
+; CHECK-NEXT:    ret <2 x i1> [[DIV]]
+;
+  %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(
+; CHECK-NEXT:    [[DIV:%.*]] = udiv <2 x i1> %x, %y
+; CHECK-NEXT:    ret <2 x i1> [[DIV]]
+;
+  %div = udiv <2 x i1> %x, %y
+  ret <2 x i1> %div
+}
+
 declare i32 @external()
 
 define i32 @div1() {
index 735e1fc..86b324e 100644 (file)
@@ -1,6 +1,48 @@
 ; NOTE: Assertions have been autogenerated by update_test_checks.py
 ; RUN: opt < %s -instsimplify -S | FileCheck %s
 
+; FIXME: Division-by-zero is undef. UB in any vector lane means the whole op is undef.
+
+define <2 x i8> @srem_zero_elt_vec(<2 x i8> %x) {
+; CHECK-LABEL: @srem_zero_elt_vec(
+; CHECK-NEXT:    [[REM:%.*]] = srem <2 x i8> %x, <i8 -42, i8 0>
+; CHECK-NEXT:    ret <2 x i8> [[REM]]
+;
+  %rem = srem <2 x i8> %x, <i8 -42, i8 0>
+  ret <2 x i8> %rem
+}
+
+define <2 x i8> @urem_zero_elt_vec(<2 x i8> %x) {
+; CHECK-LABEL: @urem_zero_elt_vec(
+; CHECK-NEXT:    [[REM:%.*]] = urem <2 x i8> %x, <i8 0, i8 42>
+; CHECK-NEXT:    ret <2 x i8> [[REM]]
+;
+  %rem = urem <2 x i8> %x, <i8 0, i8 42>
+  ret <2 x i8> %rem
+}
+
+; FIXME: Division-by-zero is undef. UB in any vector lane means the whole op is undef.
+; 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> @srem_bool_vec(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @srem_bool_vec(
+; CHECK-NEXT:    [[REM:%.*]] = srem <2 x i1> %x, %y
+; CHECK-NEXT:    ret <2 x i1> [[REM]]
+;
+  %rem = srem <2 x i1> %x, %y
+  ret <2 x i1> %rem
+}
+
+define <2 x i1> @urem_bool_vec(<2 x i1> %x, <2 x i1> %y) {
+; CHECK-LABEL: @urem_bool_vec(
+; CHECK-NEXT:    [[REM:%.*]] = urem <2 x i1> %x, %y
+; CHECK-NEXT:    ret <2 x i1> [[REM]]
+;
+  %rem = urem <2 x i1> %x, %y
+  ret <2 x i1> %rem
+}
+
 define i32 @select1(i32 %x, i1 %b) {
 ; CHECK-LABEL: @select1(
 ; CHECK-NEXT:    ret i32 0