[llvm] r297411 - [InstSimplify] allow folds for bool vector div/rem

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 9 13:56:03 PST 2017


Author: spatel
Date: Thu Mar  9 15:56:03 2017
New Revision: 297411

URL: http://llvm.org/viewvc/llvm-project?rev=297411&view=rev
Log:
[InstSimplify] allow folds for bool vector div/rem

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/div.ll
    llvm/trunk/test/Transforms/InstSimplify/rem.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=297411&r1=297410&r2=297411&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Thu Mar  9 15:56:03 2017
@@ -1052,9 +1052,9 @@ static Value *simplifyDivRem(Value *Op0,
 
   // 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;

Modified: llvm/trunk/test/Transforms/InstSimplify/div.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/div.ll?rev=297411&r1=297410&r2=297411&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/div.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/div.ll Thu Mar  9 15:56:03 2017
@@ -34,14 +34,13 @@ define <2 x i8> @udiv_zero_elt_vec(<2 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>
 
 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

Modified: llvm/trunk/test/Transforms/InstSimplify/rem.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/rem.ll?rev=297411&r1=297410&r2=297411&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/rem.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/rem.ll Thu Mar  9 15:56:03 2017
@@ -35,14 +35,13 @@ define <2 x i8> @urem_zero_elt_vec(<2 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>
 
 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




More information about the llvm-commits mailing list