An argument and a local identified object (eg. a noalias call) could turn out
equal if both are null. In the test, scope type %t and global @y by adding a
'gep' prefix to them.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151452 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 11afa85..93f5568 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -1626,21 +1626,22 @@
   LHSPtr = stripPointerAdjustments(LHSPtr);
   if (llvm::isIdentifiedObject(LHSPtr)) {
     RHSPtr = stripPointerAdjustments(RHSPtr);
-    // If both sides are different identified objects, they aren't equal unless
-    // they're null.
-    if (LHSPtr != RHSPtr && llvm::isIdentifiedObject(RHSPtr) &&
-        (llvm::isKnownNonNull(LHSPtr) || llvm::isKnownNonNull(RHSPtr)))
-      return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
+    if (llvm::isKnownNonNull(LHSPtr) || llvm::isKnownNonNull(RHSPtr)) {
+      // If both sides are different identified objects, they aren't equal
+      // unless they're null.
+      if (LHSPtr != RHSPtr && llvm::isIdentifiedObject(RHSPtr))
+        return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
 
-    // Assume that the null is on the right.
+      // A local identified object (alloca or noalias call) can't equal any
+      // incoming argument, unless they're both null.
+      if ((isa<Instruction>(LHSPtr) && isa<Argument>(RHSPtr)) ||
+          (isa<Instruction>(RHSPtr) && isa<Argument>(LHSPtr)))
+        return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
+    }
+
+    // Assume that the constant null is on the right.
     if (llvm::isKnownNonNull(LHSPtr) && isa<ConstantPointerNull>(RHSPtr))
       return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
-
-    // A local instruction (alloca or noalias call) can't equal any incoming
-    // argument.
-    if ((isa<Instruction>(LHSPtr) && isa<Argument>(RHSPtr)) ||
-        (isa<Instruction>(RHSPtr) && isa<Argument>(LHSPtr)))
-      return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
   }
 
   // If we are comparing with zero then try hard since this is a common case.