[PATCH] D78222: Transform/Float2Int: Don't rely on hack support for floating point type in ConstantRange
Jan Vesely via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 15 11:30:32 PDT 2020
jvesely created this revision.
jvesely added a reviewer: spatel.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
jvesely added a child revision: D78220: IR/ConstantRange: Add support for FP ranges.
Don't rely on ConstantRange treating float operations using integer ranges.
Opencode custom FPto{SI,UI} operations.
Floating point support for ConstantRange is added in D78220 <https://reviews.llvm.org/D78220>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D78222
Files:
llvm/lib/Transforms/Scalar/Float2Int.cpp
Index: llvm/lib/Transforms/Scalar/Float2Int.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/Float2Int.cpp
+++ llvm/lib/Transforms/Scalar/Float2Int.cpp
@@ -201,14 +201,22 @@
seen(I, badRange());
break;
- case Instruction::UIToFP:
+ case Instruction::UIToFP: {
+ // Path terminated cleanly - use the type of the integer input to seed
+ // the analysis.
+ unsigned BW = I->getOperand(0)->getType()->getPrimitiveSizeInBits();
+ APInt Min = APInt::getMinValue(BW).zextOrSelf(MaxIntegerBW + 1);
+ APInt Max = APInt::getMaxValue(BW).zextOrSelf(MaxIntegerBW + 1);
+ seen(I, validateRange(ConstantRange(std::move(Min), std::move(Max))));
+ continue;
+ }
case Instruction::SIToFP: {
// Path terminated cleanly - use the type of the integer input to seed
// the analysis.
unsigned BW = I->getOperand(0)->getType()->getPrimitiveSizeInBits();
- auto Input = ConstantRange::getFull(BW);
- auto CastOp = (Instruction::CastOps)I->getOpcode();
- seen(I, validateRange(Input.castOp(CastOp, MaxIntegerBW+1)));
+ APInt Min = APInt::getSignedMinValue(BW).sextOrSelf(MaxIntegerBW + 1);
+ APInt Max = APInt::getSignedMaxValue(BW).sextOrSelf(MaxIntegerBW + 1);
+ seen(I, validateRange(ConstantRange(std::move(Min), std::move(Max))));
continue;
}
@@ -267,7 +275,7 @@
case Instruction::FMul:
Op = [I](ArrayRef<ConstantRange> Ops) {
assert(Ops.size() == 2 && "its a binary operator!");
- auto BinOp = (Instruction::BinaryOps) I->getOpcode();
+ auto BinOp = mapBinOpcode(I->getOpcode());
return Ops[0].binaryOp(BinOp, Ops[1]);
};
break;
@@ -278,12 +286,13 @@
//
case Instruction::FPToUI:
case Instruction::FPToSI:
- Op = [I](ArrayRef<ConstantRange> Ops) {
+ Op = [I, this](ArrayRef<ConstantRange> Ops) {
assert(Ops.size() == 1 && "FPTo[US]I is a unary operator!");
// Note: We're ignoring the casts output size here as that's what the
// caller expects.
- auto CastOp = (Instruction::CastOps)I->getOpcode();
- return Ops[0].castOp(CastOp, MaxIntegerBW+1);
+ if (Ops[0].getBitWidth() == MaxIntegerBW+1)
+ return Ops[0];
+ return badRange();
};
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78222.257768.patch
Type: text/x-patch
Size: 2363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200415/0741a95a/attachment-0001.bin>
More information about the llvm-commits
mailing list