From 0a2d74bd53ae2b13f277b45aed3bb45aa87fa530 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 19 May 2008 20:27:56 +0000 Subject: [PATCH] minor cleanups, teach instcombine that sitofp/uitofp cannot produce a negative zero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51272 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 46dba398cfe..10d3344598d 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -834,10 +834,11 @@ void InstCombiner::ComputeMaskedBits(Value *V, const APInt &Mask, case Instruction::IntToPtr: // We can't handle these if we don't know the pointer size. if (!TD) return; - // Fall through and handle them the same as zext/trunc. + // FALL THROUGH and handle them the same as zext/trunc. case Instruction::ZExt: case Instruction::Trunc: { - // All these have integer operands + // Note that we handle pointer operands here because of inttoptr/ptrtoint + // which fall through here. const Type *SrcTy = I->getOperand(0)->getType(); uint32_t SrcBitWidth = TD ? TD->getTypeSizeInBits(SrcTy) : @@ -2339,13 +2340,17 @@ static bool CannotBeNegativeZero(const Value *V) { if (const ConstantFP *CFP = dyn_cast(V)) return !CFP->getValueAPF().isNegZero(); - // (add x, 0.0) is guaranteed to return +0.0, not -0.0. if (const Instruction *I = dyn_cast(V)) { + // (add x, 0.0) is guaranteed to return +0.0, not -0.0. if (I->getOpcode() == Instruction::Add && isa(I->getOperand(1)) && cast(I->getOperand(1))->isNullValue()) return true; + // sitofp and uitofp turn into +0.0 for zero. + if (isa(I) || isa(I)) + return true; + if (const IntrinsicInst *II = dyn_cast(I)) if (II->getIntrinsicID() == Intrinsic::sqrt) return CannotBeNegativeZero(II->getOperand(1));