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 | 3afc0721c766db6942e79597a9b2e10fe0824194 (patch) | |
| tree | 2b0d525efc17ad2fcffbf6f8cda0d80a7b476783 /llvm/lib | |
| parent | a529c2555560596376e77512490b4945f720d999 (diff) | |
| download | bcm5719-llvm-3afc0721c766db6942e79597a9b2e10fe0824194.tar.gz bcm5719-llvm-3afc0721c766db6942e79597a9b2e10fe0824194.zip | |
fix incorrect folding of icmp with undef, PR6481.
llvm-svn: 97659
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 7 | ||||
| -rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 2 |
2 files changed, 4 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 1f8053afe94..8288e96eb77 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/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/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index 194a6d4d8c0..47244a0e323 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/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()) |

