[llvm] r342594 - [SelectionDAG] allow vector types with isBitwiseNot()

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 19 14:48:31 PDT 2018


Author: spatel
Date: Wed Sep 19 14:48:30 2018
New Revision: 342594

URL: http://llvm.org/viewvc/llvm-project?rev=342594&view=rev
Log:
[SelectionDAG] allow vector types with isBitwiseNot()

The test diff in not-and-simplify.ll is from a use in SimplifyDemandedBits,
and the test diff in add.ll is from a DAGCombiner transform.

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

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=342594&r1=342593&r2=342594&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Wed Sep 19 14:48:30 2018
@@ -2009,10 +2009,8 @@ static SDValue foldAddSubOfSignBit(SDNod
     return SDValue();
 
   // The shift must be of a 'not' value.
-  // TODO: Use isBitwiseNot() if it works with vectors.
   SDValue Not = ShiftOp.getOperand(0);
-  if (!Not.hasOneUse() || Not.getOpcode() != ISD::XOR ||
-      !isAllOnesConstantOrAllOnesSplatConstant(Not.getOperand(1)))
+  if (!Not.hasOneUse() || !isBitwiseNot(Not))
     return SDValue();
 
   // The shift must be moving the sign bit to the least-significant-bit.

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=342594&r1=342593&r2=342594&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Wed Sep 19 14:48:30 2018
@@ -8191,7 +8191,10 @@ bool llvm::isOneConstant(SDValue V) {
 }
 
 bool llvm::isBitwiseNot(SDValue V) {
-  return V.getOpcode() == ISD::XOR && isAllOnesConstant(V.getOperand(1));
+  if (V.getOpcode() != ISD::XOR)
+    return false;
+  ConstantSDNode *C = isConstOrConstSplat(V.getOperand(1));
+  return C && C->isAllOnesValue();
 }
 
 ConstantSDNode *llvm::isConstOrConstSplat(SDValue N) {

Modified: llvm/trunk/test/CodeGen/X86/add.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/add.ll?rev=342594&r1=342593&r2=342594&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/add.ll (original)
+++ llvm/trunk/test/CodeGen/X86/add.ll Wed Sep 19 14:48:30 2018
@@ -430,17 +430,15 @@ define <4 x i32> @inc_not_vec(<4 x i32>
 ;
 ; X64-LINUX-LABEL: inc_not_vec:
 ; X64-LINUX:       # %bb.0:
-; X64-LINUX-NEXT:    pcmpeqd %xmm1, %xmm1
-; X64-LINUX-NEXT:    pxor %xmm1, %xmm0
-; X64-LINUX-NEXT:    psubd %xmm1, %xmm0
+; X64-LINUX-NEXT:    pxor %xmm1, %xmm1
+; X64-LINUX-NEXT:    psubd %xmm0, %xmm1
+; X64-LINUX-NEXT:    movdqa %xmm1, %xmm0
 ; X64-LINUX-NEXT:    retq
 ;
 ; X64-WIN32-LABEL: inc_not_vec:
 ; X64-WIN32:       # %bb.0:
-; X64-WIN32-NEXT:    pcmpeqd %xmm1, %xmm1
-; X64-WIN32-NEXT:    movdqa (%rcx), %xmm0
-; X64-WIN32-NEXT:    pxor %xmm1, %xmm0
-; X64-WIN32-NEXT:    psubd %xmm1, %xmm0
+; X64-WIN32-NEXT:    pxor %xmm0, %xmm0
+; X64-WIN32-NEXT:    psubd (%rcx), %xmm0
 ; X64-WIN32-NEXT:    retq
   %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 -1, i32 -1>
   %r = add <4 x i32> %nota, <i32 1, i32 1, i32 1, i32 1>

Modified: llvm/trunk/test/CodeGen/X86/not-and-simplify.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/not-and-simplify.ll?rev=342594&r1=342593&r2=342594&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/not-and-simplify.ll (original)
+++ llvm/trunk/test/CodeGen/X86/not-and-simplify.ll Wed Sep 19 14:48:30 2018
@@ -21,7 +21,7 @@ define <4 x i32> @shrink_xor_constant1_s
 ; ALL-LABEL: shrink_xor_constant1_splat:
 ; ALL:       # %bb.0:
 ; ALL-NEXT:    psrld $31, %xmm0
-; ALL-NEXT:    pandn {{.*}}(%rip), %xmm0
+; ALL-NEXT:    pxor {{.*}}(%rip), %xmm0
 ; ALL-NEXT:    retq
   %sh = lshr <4 x i32> %x, <i32 31, i32 31, i32 31, i32 31>
   %not = xor <4 x i32> %sh, <i32 -1, i32 -1, i32 -1, i32 -1>




More information about the llvm-commits mailing list