Index: test/SemaCXX/warn-logical-not-compare.cpp
===================================================================
--- test/SemaCXX/warn-logical-not-compare.cpp	(revision 0)
+++ test/SemaCXX/warn-logical-not-compare.cpp	(revision 0)
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -fsyntax-only -Wlogical-not-compare -verify %s
+
+bool getBool();
+int getInt();
+
+bool test1(int i1, int i2, bool b1, bool b2) {
+  bool ret;
+
+  ret = !i1 == i2; // \
+// expected-warning{{logical not is only applied to the left hand side of this comparison}} \
+// expected-note{{did you mean to drop the '!' and negate the condition by using '!=' instead of '=='?}} \
+// expected-note{{add parenthesis around left hand side expression to silence}}
+
+  ret = !i1 != i2; // \
+//expected-warning{{logical not is only applied to the left hand side of this comparison}} \
+// expected-note{{did you mean to drop the '!' and negate the condition by using '==' instead of '!='?}} \
+// expected-note{{add parenthesis around left hand side expression to silence}}
+
+  ret = !i1 < i2; // \
+//expected-warning{{logical not is only applied to the left hand side of this comparison}} \
+// expected-note{{did you mean to drop the '!' and negate the condition by using '>=' instead of '<'?}} \
+// expected-note{{add parenthesis around left hand side expression to silence}}
+
+  ret = !i1 > i2; // \
+//expected-warning{{logical not is only applied to the left hand side of this comparison}} \
+// expected-note{{did you mean to drop the '!' and negate the condition by using '<=' instead of '>'?}} \
+// expected-note{{add parenthesis around left hand side expression to silence}}
+
+  ret = !i1 <= i2; // \
+//expected-warning{{logical not is only applied to the left hand side of this comparison}} \
+// expected-note{{did you mean to drop the '!' and negate the condition by using '>' instead of '<='?}} \
+// expected-note{{add parenthesis around left hand side expression to silence}}
+
+  ret = !i1 >= i2; // \
+//expected-warning{{logical not is only applied to the left hand side of this comparison}} \
+// expected-note{{did you mean to drop the '!' and negate the condition by using '<' instead of '>='?}} \
+// expected-note{{add parenthesis around left hand side expression to silence}}
+
+  ret = i1 == i2;
+  ret = i1 != i2;
+  ret = i1 < i2;
+  ret = i1 > i2;
+  ret = i1 <= i2;
+  ret = i1 >= i2;
+
+  // Warning silenced by parens.
+  ret = (!i1) == i2;
+  ret = (!i1) != i2;
+  ret = (!i1) < i2;
+  ret = (!i1) > i2;
+  ret = (!i1) <= i2;
+  ret = (!i1) >= i2;
+
+  ret = !b1 == b2;
+  ret = !b1 != b2;
+  ret = !b1 < b2;
+  ret = !b1 > b2;
+  ret = !b1 <= b2;
+  ret = !b1 >= b2;
+
+  ret = !getInt() == i1; // \
+// expected-warning{{logical not is only applied to the left hand side of this comparison}} \
+// expected-note{{did you mean to drop the '!' and negate the condition by using '!=' instead of '=='?}} \
+// expected-note{{add parenthesis around left hand side expression to silence}}
+
+  ret = (!getInt()) == i1;
+  ret = !getBool() == b1;
+  return ret;
+}
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td	(revision 165753)
+++ include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -4117,6 +4117,14 @@
   "comparison between NULL and non-pointer "
   "%select{(%1 and NULL)|(NULL and %1)}0">,
   InGroup<DiagGroup<"null-arithmetic">>;
+def warn_logical_not_on_lhs_of_comparison : Warning<
+  "logical not is only applied to the left hand side of this comparison">,
+  InGroup<DiagGroup<"logical-not-compare">>;
+def note_logical_not_fix : Note<
+  "did you mean to drop the '!' and negate the condition by using '%0' "
+  "instead of '%1'?">;
+def note_logical_not_silence_with_parens : Note<
+  "add parenthesis around left hand side expression to silence">;
 
 def err_invalid_this_use : Error<
   "invalid use of 'this' outside of a non-static member function">;
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp	(revision 165753)
+++ lib/Sema/SemaExpr.cpp	(working copy)
@@ -6924,6 +6924,55 @@
   }
 }
 
+static void diagnoseLogicalNotOnLHSofComparison(Sema &S, ExprResult &LHS,
+                                                ExprResult &RHS,
+                                                SourceLocation Loc,
+                                                unsigned OpaqueOpc) {
+  // This checking requires bools.
+  if (!S.getLangOpts().Bool) return;
+
+  // Only check if the right hand side is non-bool arithmetic type.
+  if (RHS.get()->getType()->isBooleanType()) return;
+
+  // Check that left hand side is !something.
+  UnaryOperator *UO = dyn_cast<UnaryOperator>(LHS.get());
+  if (!UO || UO->getOpcode() != UO_LNot) return;
+
+  // Make sure that the something in !something is not bool.
+  Expr *SubExpr = UO->getSubExpr()->IgnoreImpCasts();
+  if (SubExpr->getType()->isBooleanType()) return;
+
+  // Get the inverse of the comparison sign. 
+  StringRef NewOp, OldOp;
+  switch (OpaqueOpc) {
+    case BO_LT: NewOp = ">="; OldOp = "<"; break;
+    case BO_GT: NewOp = "<="; OldOp = ">"; break;
+    case BO_LE: NewOp = ">"; OldOp = "<="; break;
+    case BO_GE: NewOp = "<"; OldOp = ">="; break;
+    case BO_EQ: NewOp = "!="; OldOp = "=="; break;
+    case BO_NE: NewOp = "=="; OldOp = "!="; break;
+    default: llvm_unreachable("Invalid operator type");
+  }
+
+  // Emit warning.
+  S.Diag(UO->getOperatorLoc(), diag::warn_logical_not_on_lhs_of_comparison)
+      << Loc;
+
+  // First note has fix-it to remove '!' and flip the comparison.
+  S.Diag(UO->getOperatorLoc(), diag::note_logical_not_fix)
+      << NewOp << OldOp
+      << FixItHint::CreateRemoval(UO->getOperatorLoc())
+      << FixItHint::CreateReplacement(Loc, NewOp);
+
+  // Second note suggests parens around !something to silence warning.
+  SourceLocation Open = LHS.get()->getLocStart();
+  SourceLocation Close = LHS.get()->getSourceRange().getEnd();
+  Close = S.getPreprocessor().getLocForEndOfToken(Close);
+  S.Diag(UO->getOperatorLoc(), diag::note_logical_not_silence_with_parens)
+      << FixItHint::CreateInsertion(Open, "(")
+      << FixItHint::CreateInsertion(Close, ")");
+}
+
 // C99 6.5.8, C++ [expr.rel]
 QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
                                     SourceLocation Loc, unsigned OpaqueOpc,
@@ -6944,6 +6993,7 @@
   Expr *RHSStripped = RHS.get()->IgnoreParenImpCasts();
 
   checkEnumComparison(*this, Loc, LHS, RHS);
+  diagnoseLogicalNotOnLHSofComparison(*this, LHS, RHS, Loc, OpaqueOpc);
 
   if (!LHSType->hasFloatingRepresentation() &&
       !(LHSType->isBlockPointerType() && IsRelational) &&
