[DAGCombiner] Generalize (and (or x, C), D) -> D iff (C & D) == D combine to work...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 21 Dec 2017 15:17:29 +0000 (15:17 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 21 Dec 2017 15:17:29 +0000 (15:17 +0000)
llvm-svn: 321275

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

index cc8edb7..e8f76a2 100644 (file)
@@ -3998,10 +3998,12 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
   if (SDValue RAND = ReassociateOps(ISD::AND, SDLoc(N), N0, N1))
     return RAND;
   // fold (and (or x, C), D) -> D if (C & D) == D
-  if (N1C && N0.getOpcode() == ISD::OR)
-    if (ConstantSDNode *ORI = isConstOrConstSplat(N0.getOperand(1)))
-      if (N1C->getAPIntValue().isSubsetOf(ORI->getAPIntValue()))
-        return N1;
+  auto MatchSubset = [](ConstantSDNode *LHS, ConstantSDNode *RHS) {
+    return RHS->getAPIntValue().isSubsetOf(LHS->getAPIntValue());
+  };
+  if (N0.getOpcode() == ISD::OR &&
+      matchBinaryPredicate(N0.getOperand(1), N1, MatchSubset))
+    return N1;
   // fold (and (any_ext V), c) -> (zero_ext V) if 'and' only clears top bits.
   if (N1C && N0.getOpcode() == ISD::ANY_EXTEND) {
     SDValue N0Op0 = N0.getOperand(0);
index df89ee4..c2da74a 100644 (file)
@@ -223,8 +223,7 @@ define <4 x i32> @and_or_v4i32(<4 x i32> %a0) {
 define <8 x i16> @and_or_v8i16(<8 x i16> %a0) {
 ; CHECK-LABEL: and_or_v8i16:
 ; CHECK:       # %bb.0:
-; CHECK-NEXT:    orps {{.*}}(%rip), %xmm0
-; CHECK-NEXT:    andps {{.*}}(%rip), %xmm0
+; CHECK-NEXT:    movaps {{.*#+}} xmm0 = [15,7,3,1,14,10,2,32767]
 ; CHECK-NEXT:    retq
   %1 = or <8 x i16> %a0, <i16 255, i16 127, i16 63, i16 31, i16 15, i16 31, i16 63, i16 -1>
   %2 = and <8 x i16> %1, <i16 15, i16 7, i16 3, i16 1, i16 14, i16 10, i16 2, i16 32767>