Partial fix for PR1678: correct some parts of constant

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
This commit is contained in:
Duncan Sands 2007-09-19 10:16:17 +00:00
parent 892c7e4a23
commit 7801644332

View 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)