diff options
author | Chris Lattner <sabre@nondot.org> | 2010-03-03 19:46:03 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-03-03 19:46:03 +0000 |
commit | c8e14b3d37b80abb6adb4b831af0452d9ecbf2b2 (patch) | |
tree | 82f5c1caf2f2072cfb903e28fbde8df7b103e0c7 /lib | |
parent | fec8657351346966e48f9248079e85602dc1f85d (diff) |
fix incorrect folding of icmp with undef, PR6481.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97659 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/InstructionSimplify.cpp | 7 | ||||
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 2 |
2 files changed, 4 insertions, 5 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index 1f8053afe9..8288e96eb7 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -194,11 +194,10 @@ Value *llvm::SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, const Type *ITy = GetCompareTy(LHS); // icmp X, X -> true/false - if (LHS == RHS) + // X icmp undef -> true/false. For example, icmp ugt %X, undef -> false + // because X could be 0. + if (LHS == RHS || isa<UndefValue>(RHS)) return ConstantInt::get(ITy, CmpInst::isTrueWhenEqual(Pred)); - - if (isa<UndefValue>(RHS)) // X icmp undef -> undef - return UndefValue::get(ITy); // icmp <global/alloca*/null>, <global/alloca*/null> - Global/Stack value // addresses never equal each other! We already know that Op0 != Op1. diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 194a6d4d8c..47244a0e32 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -1818,7 +1818,7 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred, // Handle some degenerate cases first if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) - return UndefValue::get(ResultTy); + return ConstantInt::get(ResultTy, CmpInst::isTrueWhenEqual(pred)); // No compile-time operations on this type yet. if (C1->getType()->isPPC_FP128Ty()) |