]> granicus.if.org Git - llvm/commitdiff
[InstSimplify] allow folds for bool vector div/rem
authorSanjay Patel <spatel@rotateright.com>
Thu, 9 Mar 2017 21:56:03 +0000 (21:56 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 9 Mar 2017 21:56:03 +0000 (21:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297411 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/div.ll
test/Transforms/InstSimplify/rem.ll

index f63b1aea795e8a53c3c189833705e7cf91347f91..08afafa74573a292a45a3dca19214f63a139006e 100644 (file)
@@ -1052,9 +1052,9 @@ static Value *simplifyDivRem(Value *Op0, Value *Op1, bool IsDiv) {
 
   // X / 1 -> X
   // X % 1 -> 0
-  // If this is a boolean op (single-bit type), we can't have division-by-zero
-  // or remainder-by-zero, so assume the divisor is 1.
-  if (match(Op1, m_One()) || Ty->isIntegerTy(1))
+  // If this is a boolean op (single-bit element type), we can't have
+  // division-by-zero or remainder-by-zero, so assume the divisor is 1.
+  if (match(Op1, m_One()) || Ty->getScalarType()->isIntegerTy(1))
     return IsDiv ? Op0 : Constant::getNullValue(Ty);
 
   return nullptr;
index 560d3eea9331ab330f94003e729e697c2fb52bfe..f096719359dcde37c53aea74692e46734dd867ff 100644 (file)
@@ -34,14 +34,13 @@ define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {
   ret <2 x i8> %div
 }
 
-; FIXME: Division-by-zero is undef. UB in any vector lane means the whole op is undef.
+; 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]]
+; CHECK-NEXT:    ret <2 x i1> %x
 ;
   %div = sdiv <2 x i1> %x, %y
   ret <2 x i1> %div
@@ -49,8 +48,7 @@ define <2 x i1> @sdiv_bool_vec(<2 x i1> %x, <2 x i1> %y) {
 
 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]]
+; CHECK-NEXT:    ret <2 x i1> %x
 ;
   %div = udiv <2 x i1> %x, %y
   ret <2 x i1> %div
index c60b728cad2a51c66da92e1c709994f93416dcbc..b7f18f36b4b98631dd1ea1f067bd22ab2fdd319c 100644 (file)
@@ -35,14 +35,13 @@ define <2 x i8> @urem_zero_elt_vec(<2 x i8> %x) {
   ret <2 x i8> %rem
 }
 
-; FIXME: Division-by-zero is undef. UB in any vector lane means the whole op is undef.
+; 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]]
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
 ;
   %rem = srem <2 x i1> %x, %y
   ret <2 x i1> %rem
@@ -50,8 +49,7 @@ define <2 x i1> @srem_bool_vec(<2 x i1> %x, <2 x i1> %y) {
 
 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]]
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
 ;
   %rem = urem <2 x i1> %x, %y
   ret <2 x i1> %rem