From cbfca9e8efcfd468af6047f0dd772dac53f2a59e Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 8 Jul 2016 17:01:15 +0000 Subject: [PATCH] [InstCombine] allow or(sext(A), B) --> A ? -1 : B transform for vectors llvm-svn: 274883 --- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 9 +++++---- llvm/test/Transforms/InstCombine/or.ll | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index b5b320f29c52..f6ec03b9721a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2393,11 +2393,12 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { if (Instruction *CastedOr = foldCastedBitwiseLogic(I)) return CastedOr; - // or(sext(A), B) -> A ? -1 : B where A is an i1 - // or(A, sext(B)) -> B ? -1 : A where B is an i1 - if (match(Op0, m_SExt(m_Value(A))) && A->getType()->isIntegerTy(1)) + // or(sext(A), B) / or(B, sext(A)) --> A ? -1 : B, where A is i1 or . + if (match(Op0, m_SExt(m_Value(A))) && + A->getType()->getScalarType()->isIntegerTy(1)) return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op1); - if (match(Op1, m_SExt(m_Value(A))) && A->getType()->isIntegerTy(1)) + if (match(Op1, m_SExt(m_Value(A))) && + A->getType()->getScalarType()->isIntegerTy(1)) return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op0); // Note: If we've gotten to the point of visiting the outer OR, then the diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll index 779edd635287..8cec10c1f655 100644 --- a/llvm/test/Transforms/InstCombine/or.ll +++ b/llvm/test/Transforms/InstCombine/or.ll @@ -447,8 +447,7 @@ define i32 @orsext_to_sel_swap(i32 %x, i1 %y) { define <2 x i32> @orsext_to_sel_vec(<2 x i32> %x, <2 x i1> %y) { ; CHECK-LABEL: @orsext_to_sel_vec( -; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i1> %y to <2 x i32> -; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[SEXT]], %x +; CHECK-NEXT: [[OR:%.*]] = select <2 x i1> %y, <2 x i32> , <2 x i32> %x ; CHECK-NEXT: ret <2 x i32> [[OR]] ; %sext = sext <2 x i1> %y to <2 x i32> @@ -458,8 +457,7 @@ define <2 x i32> @orsext_to_sel_vec(<2 x i32> %x, <2 x i1> %y) { define <2 x i132> @orsext_to_sel_vec_swap(<2 x i132> %x, <2 x i1> %y) { ; CHECK-LABEL: @orsext_to_sel_vec_swap( -; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i1> %y to <2 x i132> -; CHECK-NEXT: [[OR:%.*]] = or <2 x i132> [[SEXT]], %x +; CHECK-NEXT: [[OR:%.*]] = select <2 x i1> %y, <2 x i132> , <2 x i132> %x ; CHECK-NEXT: ret <2 x i132> [[OR]] ; %sext = sext <2 x i1> %y to <2 x i132>