Fixes untainted branch that is immediately after relaxed loads
[oota-llvm.git] / lib / CodeGen / SelectionDAG / DAGCombiner.cpp
index 86732bb6ffc356b8a1b45277704c28f89352b568..bdcf5a2a89ece0a68e8186b29ed9bd63babf6907 100644 (file)
@@ -3100,9 +3100,19 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
   ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
 
   // XXX-disabled: (and x, 0) should not be folded.
+  // (and (and x, 0), y) shouldn't either.
   if (!N0C && N1C->isNullValue()) {
     return SDValue();
   }
+  if (!N0C) {
+    if (N0.getOpcode() == ISD::AND) {
+      auto* N01 = N0.getOperand(1).getNode();
+      auto* N01C = dyn_cast<ConstantSDNode>(N01);
+      if (N01C && N01C->isNullValue()) {
+        return SDValue();
+      }
+    }
+  }
 
   if (N0C && N1C && !N1C->isOpaque())
     return DAG.FoldConstantArithmetic(ISD::AND, SDLoc(N), VT, N0C, N1C);