From 2d2e7861b5aeb18b189abe95d0cbbd6e01b2deb2 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sun, 30 Nov 2008 12:38:24 +0000 Subject: getSExtValue() doesn't work for ConstantInts with bitwidth > 64 bits. Use all APInt calls instead. This fixes PR3144. llvm-svn: 60288 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index f3cb747e56f..93510f0593f 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2957,21 +2957,21 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { return BinaryOperator::CreateNeg(Op0); ConstantInt *RHSNeg = cast(ConstantExpr::getNeg(RHS)); - APInt RHSNegAPI(RHSNeg->getBitWidth(), RHSNeg->getSExtValue(), true); + APInt RHSNegAPI(RHSNeg->getValue()); APInt NegOne = -APInt(RHSNeg->getBitWidth(), 1, true); APInt TwoToExp(RHSNeg->getBitWidth(), 1 << (RHSNeg->getBitWidth() - 1)); // -X/C -> X/-C, if and only if negation doesn't overflow. - if ((RHS->getSExtValue() < 0 && RHSNegAPI.slt(TwoToExp - 1)) || - (RHS->getSExtValue() > 0 && RHSNegAPI.sgt(TwoToExp * NegOne))) { + if ((RHS->getValue().isNegative() && RHSNegAPI.slt(TwoToExp - 1)) || + (RHS->getValue().isNonNegative() && RHSNegAPI.sgt(TwoToExp * NegOne))) { if (Value *LHSNeg = dyn_castNegVal(Op0)) { if (ConstantInt *CI = dyn_cast(LHSNeg)) { ConstantInt *CINeg = cast(ConstantExpr::getNeg(CI)); APInt CINegAPI(CINeg->getBitWidth(), CINeg->getSExtValue(), true); - if ((CI->getSExtValue() < 0 && CINegAPI.slt(TwoToExp - 1)) || - (CI->getSExtValue() > 0 && CINegAPI.sgt(TwoToExp * NegOne))) + if ((CI->getValue().isNegative() && CINegAPI.slt(TwoToExp - 1)) || + (CI->getValue().isNonNegative() && CINegAPI.sgt(TwoToExp*NegOne))) return BinaryOperator::CreateSDiv(LHSNeg, ConstantExpr::getNeg(RHS)); } -- cgit v1.2.3