From: Sanjay Patel Date: Thu, 9 Mar 2017 21:56:03 +0000 (+0000) Subject: [InstSimplify] allow folds for bool vector div/rem X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e1f925ba955bb66fa75bb01747ceb4fd2520ee9;p=llvm [InstSimplify] allow folds for bool vector div/rem git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297411 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index f63b1aea795..08afafa7457 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -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; diff --git a/test/Transforms/InstSimplify/div.ll b/test/Transforms/InstSimplify/div.ll index 560d3eea933..f096719359d 100644 --- a/test/Transforms/InstSimplify/div.ll +++ b/test/Transforms/InstSimplify/div.ll @@ -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 diff --git a/test/Transforms/InstSimplify/rem.ll b/test/Transforms/InstSimplify/rem.ll index c60b728cad2..b7f18f36b4b 100644 --- a/test/Transforms/InstSimplify/rem.ll +++ b/test/Transforms/InstSimplify/rem.ll @@ -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