OSDN Git Service

Partial fix for PR1678: correct some parts of constant
authorDuncan Sands <baldrick@free.fr>
Wed, 19 Sep 2007 10:16:17 +0000 (10:16 +0000)
committerDuncan Sands <baldrick@free.fr>
Wed, 19 Sep 2007 10:16:17 +0000 (10:16 +0000)
fold that were missed in the fix for PR1646.  Probably
this null/not-null logic should be factorized somewhere.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42131 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp

index 5c80a37..a61dd06 100644 (file)
@@ -1124,7 +1124,8 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
   // icmp eq/ne(null,GV) -> false/true
   if (C1->isNullValue()) {
     if (const GlobalValue *GV = dyn_cast<GlobalValue>(C2))
-      if (!GV->hasExternalWeakLinkage()) // External weak GV can be null
+      // Don't try to evaluate aliases.  External weak GV can be null.
+      if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage())
         if (pred == ICmpInst::ICMP_EQ)
           return ConstantInt::getFalse();
         else if (pred == ICmpInst::ICMP_NE)
@@ -1132,7 +1133,8 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
   // icmp eq/ne(GV,null) -> false/true
   } else if (C2->isNullValue()) {
     if (const GlobalValue *GV = dyn_cast<GlobalValue>(C1))
-      if (!GV->hasExternalWeakLinkage()) // External weak GV can be null
+      // Don't try to evaluate aliases.  External weak GV can be null.
+      if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage())
         if (pred == ICmpInst::ICMP_EQ)
           return ConstantInt::getFalse();
         else if (pred == ICmpInst::ICMP_NE)