[llvm] r308098 - [InstCombine] allow (0 - x) & 1 --> x & 1 for vectors
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 15 08:29:47 PDT 2017
Author: spatel
Date: Sat Jul 15 08:29:47 2017
New Revision: 308098
URL: http://llvm.org/viewvc/llvm-project?rev=308098&view=rev
Log:
[InstCombine] allow (0 - x) & 1 --> x & 1 for vectors
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/test/Transforms/InstCombine/and2.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=308098&r1=308097&r2=308098&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Sat Jul 15 08:29:47 2017
@@ -1284,6 +1284,11 @@ Instruction *InstCombiner::visitAnd(Bina
if (Value *V = SimplifyBSwap(I, Builder))
return replaceInstUsesWith(I, V);
+ // (0 - x) & 1 --> x & 1
+ Value *X;
+ if (match(Op1, m_One()) && match(Op0, m_Sub(m_Zero(), m_Value(X))))
+ return BinaryOperator::CreateAnd(X, Op1);
+
if (ConstantInt *AndRHS = dyn_cast<ConstantInt>(Op1)) {
const APInt &AndRHSMask = AndRHS->getValue();
@@ -1315,12 +1320,6 @@ Instruction *InstCombiner::visitAnd(Bina
break;
}
- case Instruction::Sub:
- // -x & 1 -> x & 1
- if (AndRHSMask.isOneValue() && match(Op0LHS, m_Zero()))
- return BinaryOperator::CreateAnd(Op0RHS, AndRHS);
-
- break;
case Instruction::Shl:
case Instruction::LShr:
Modified: llvm/trunk/test/Transforms/InstCombine/and2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/and2.ll?rev=308098&r1=308097&r2=308098&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/and2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/and2.ll Sat Jul 15 08:29:47 2017
@@ -98,8 +98,7 @@ define i64 @test9(i64 %x) {
; combine -x & 1 into x & 1
define <2 x i64> @test9vec(<2 x i64> %x) {
; CHECK-LABEL: @test9vec(
-; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i64> zeroinitializer, [[X:%.*]]
-; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> [[SUB]], <i64 1, i64 1>
+; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> %x, <i64 1, i64 1>
; CHECK-NEXT: ret <2 x i64> [[AND]]
;
%sub = sub nsw <2 x i64> <i64 0, i64 0>, %x
More information about the llvm-commits
mailing list