[llvm] r285521 - [DAG] x & x --> x

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 30 11:13:31 PDT 2016


Author: spatel
Date: Sun Oct 30 13:13:30 2016
New Revision: 285521

URL: http://llvm.org/viewvc/llvm-project?rev=285521&view=rev
Log:
[DAG] x & x --> x

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/trunk/test/CodeGen/X86/combine-and.ll

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=285521&r1=285520&r2=285521&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Sun Oct 30 13:13:30 2016
@@ -3134,6 +3134,10 @@ SDValue DAGCombiner::visitAND(SDNode *N)
   SDValue N1 = N->getOperand(1);
   EVT VT = N1.getValueType();
 
+  // x & x --> x
+  if (N0 == N1)
+    return N0;
+
   // fold vector ops
   if (VT.isVector()) {
     if (SDValue FoldedVOp = SimplifyVBinOp(N))

Modified: llvm/trunk/test/CodeGen/X86/combine-and.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/combine-and.ll?rev=285521&r1=285520&r2=285521&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/combine-and.ll (original)
+++ llvm/trunk/test/CodeGen/X86/combine-and.ll Sun Oct 30 13:13:30 2016
@@ -4,7 +4,6 @@
 define i32 @and_self(i32 %x) {
 ; CHECK-LABEL: and_self:
 ; CHECK:       # BB#0:
-; CHECK-NEXT:    andl %edi, %edi
 ; CHECK-NEXT:    movl %edi, %eax
 ; CHECK-NEXT:    retq
   %and = and i32 %x, %x
@@ -14,7 +13,6 @@ define i32 @and_self(i32 %x) {
 define <4 x i32> @and_self_vec(<4 x i32> %x) {
 ; CHECK-LABEL: and_self_vec:
 ; CHECK:       # BB#0:
-; CHECK-NEXT:    andps %xmm0, %xmm0
 ; CHECK-NEXT:    retq
   %and = and <4 x i32> %x, %x
   ret <4 x i32> %and




More information about the llvm-commits mailing list