diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
commit | e6d1592492a3a379186bfb02bd0f4eda0669c0d5 (patch) | |
tree | 599ab169a01f1c86eda9adc774edaedde2f2db5b /lib/Transforms/Scalar/Float2Int.cpp | |
parent | 1a56a5ead7a2e84bee8240f5f6b033b5f1707154 (diff) |
Diffstat (limited to 'lib/Transforms/Scalar/Float2Int.cpp')
-rw-r--r-- | lib/Transforms/Scalar/Float2Int.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/Transforms/Scalar/Float2Int.cpp b/lib/Transforms/Scalar/Float2Int.cpp index f2828e80bc58..4f83e869b303 100644 --- a/lib/Transforms/Scalar/Float2Int.cpp +++ b/lib/Transforms/Scalar/Float2Int.cpp @@ -1,9 +1,8 @@ //===- Float2Int.cpp - Demote floating point ops to work on integers ------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -148,10 +147,10 @@ void Float2IntPass::seen(Instruction *I, ConstantRange R) { // Helper - get a range representing a poison value. ConstantRange Float2IntPass::badRange() { - return ConstantRange(MaxIntegerBW + 1, true); + return ConstantRange::getFull(MaxIntegerBW + 1); } ConstantRange Float2IntPass::unknownRange() { - return ConstantRange(MaxIntegerBW + 1, false); + return ConstantRange::getEmpty(MaxIntegerBW + 1); } ConstantRange Float2IntPass::validateRange(ConstantRange R) { if (R.getBitWidth() > MaxIntegerBW + 1) @@ -195,12 +194,13 @@ void Float2IntPass::walkBackwards(const SmallPtrSetImpl<Instruction*> &Roots) { // Path terminated cleanly - use the type of the integer input to seed // the analysis. unsigned BW = I->getOperand(0)->getType()->getPrimitiveSizeInBits(); - auto Input = ConstantRange(BW, true); + auto Input = ConstantRange::getFull(BW); auto CastOp = (Instruction::CastOps)I->getOpcode(); seen(I, validateRange(Input.castOp(CastOp, MaxIntegerBW+1))); continue; } + case Instruction::FNeg: case Instruction::FAdd: case Instruction::FSub: case Instruction::FMul: @@ -241,6 +241,15 @@ void Float2IntPass::walkForwards() { case Instruction::SIToFP: llvm_unreachable("Should have been handled in walkForwards!"); + case Instruction::FNeg: + Op = [](ArrayRef<ConstantRange> Ops) { + assert(Ops.size() == 1 && "FNeg is a unary operator!"); + unsigned Size = Ops[0].getBitWidth(); + auto Zero = ConstantRange(APInt::getNullValue(Size)); + return Zero.sub(Ops[0]); + }; + break; + case Instruction::FAdd: case Instruction::FSub: case Instruction::FMul: @@ -427,7 +436,7 @@ Value *Float2IntPass::convert(Instruction *I, Type *ToTy) { } else if (Instruction *VI = dyn_cast<Instruction>(V)) { NewOperands.push_back(convert(VI, ToTy)); } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) { - APSInt Val(ToTy->getPrimitiveSizeInBits(), /*IsUnsigned=*/false); + APSInt Val(ToTy->getPrimitiveSizeInBits(), /*isUnsigned=*/false); bool Exact; CF->getValueAPF().convertToInteger(Val, APFloat::rmNearestTiesToEven, @@ -467,6 +476,10 @@ Value *Float2IntPass::convert(Instruction *I, Type *ToTy) { NewV = IRB.CreateSExtOrTrunc(NewOperands[0], ToTy); break; + case Instruction::FNeg: + NewV = IRB.CreateNeg(NewOperands[0], I->getName()); + break; + case Instruction::FAdd: case Instruction::FSub: case Instruction::FMul: |