From 5bc253c8f2a8338f71b09462109859d7aae99029 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 13 Jan 2008 20:59:02 +0000 Subject: Fix PR1907, a nasty miscompilation because instcombine didn't realize that ne & sgt was a signed comparison (it was only looking at whether the left compare was signed). llvm-svn: 45937 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index ea53aec76cb..9465a31d29d 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -3495,8 +3495,14 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { ICmpInst::isSignedPredicate(LHSCC) == ICmpInst::isSignedPredicate(RHSCC))) { // Ensure that the larger constant is on the RHS. - ICmpInst::Predicate GT = ICmpInst::isSignedPredicate(LHSCC) ? - ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; + ICmpInst::Predicate GT; + if (ICmpInst::isSignedPredicate(LHSCC) || + (ICmpInst::isEquality(LHSCC) && + ICmpInst::isSignedPredicate(RHSCC))) + GT = ICmpInst::ICMP_SGT; + else + GT = ICmpInst::ICMP_UGT; + Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst); ICmpInst *LHS = cast(Op0); if (cast(Cmp)->getZExtValue()) { -- cgit v1.2.3