[llvm] r341410 - [InstCombine] make ((X & C) ^ C) form consistent for vectors

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 14:17:14 PDT 2018


Author: spatel
Date: Tue Sep  4 14:17:14 2018
New Revision: 341410

URL: http://llvm.org/viewvc/llvm-project?rev=341410&view=rev
Log:
[InstCombine] make ((X & C) ^ C) form consistent for vectors

It would be better to create a 'not' here, but that's not possible yet.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    llvm/trunk/test/Transforms/InstCombine/zext.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=341410&r1=341409&r2=341410&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Tue Sep  4 14:17:14 2018
@@ -2784,12 +2784,10 @@ Instruction *InstCombiner::visitXor(Bina
     return BinaryOperator::CreateAnd(Op0, Builder.CreateNot(X));
   // (X & Y) ^ Y --> ~X & Y
   // (Y & X) ^ Y --> ~X & Y
-  // Canonical form with a non-splat constant is (X & C) ^ C; don't touch that.
-  // TODO: Why do we treat arbitrary vector constants differently?
+  // Canonical form is (X & C) ^ C; don't touch that.
   // TODO: A 'not' op is better for analysis and codegen, but demanded bits must
   //       be fixed to prefer that (otherwise we get infinite looping).
-  const APInt *Unused;
-  if (!match(Op1, m_APInt(Unused)) &&
+  if (!match(Op1, m_Constant()) &&
       match(Op0, m_OneUse(m_c_And(m_Value(X), m_Specific(Op1)))))
     return BinaryOperator::CreateAnd(Op1, Builder.CreateNot(X));
 

Modified: llvm/trunk/test/Transforms/InstCombine/zext.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/zext.ll?rev=341410&r1=341409&r2=341410&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/zext.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/zext.ll Tue Sep  4 14:17:14 2018
@@ -35,8 +35,8 @@ define <2 x i64> @test3(<2 x i64> %A) {
 
 define <2 x i64> @test4(<2 x i64> %A) {
 ; CHECK-LABEL: @test4(
-; CHECK-NEXT:    [[TMP1:%.*]] = xor <2 x i64> %A, <i64 63, i64 63>
-; CHECK-NEXT:    [[XOR:%.*]] = and <2 x i64> [[TMP1]], <i64 23, i64 42>
+; CHECK-NEXT:    [[AND:%.*]] = and <2 x i64> [[A:%.*]], <i64 23, i64 42>
+; CHECK-NEXT:    [[XOR:%.*]] = xor <2 x i64> [[AND]], <i64 23, i64 42>
 ; CHECK-NEXT:    ret <2 x i64> [[XOR]]
 ;
   %trunc = trunc <2 x i64> %A to <2 x i32>




More information about the llvm-commits mailing list