[PATCH] D47807: Make uitofp and sitofp defined on overflow.
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 14 16:03:18 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334777: Make uitofp and sitofp defined on overflow. (authored by efriedma, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D47807?vs=150181&id=151435#toc
Repository:
rL LLVM
https://reviews.llvm.org/D47807
Files:
llvm/trunk/docs/LangRef.rst
llvm/trunk/lib/IR/ConstantFold.cpp
llvm/trunk/test/Transforms/ConstProp/cast.ll
Index: llvm/trunk/docs/LangRef.rst
===================================================================
--- llvm/trunk/docs/LangRef.rst
+++ llvm/trunk/docs/LangRef.rst
@@ -3288,14 +3288,12 @@
Convert an unsigned integer constant to the corresponding
floating-point constant. TYPE must be a scalar or vector floating-point
type. CST must be of scalar or vector integer type. Both CST and TYPE must
- be scalars, or vectors of the same number of elements. If the value
- won't fit in the floating-point type, the results are undefined.
+ be scalars, or vectors of the same number of elements.
``sitofp (CST to TYPE)``
Convert a signed integer constant to the corresponding floating-point
constant. TYPE must be a scalar or vector floating-point type.
CST must be of scalar or vector integer type. Both CST and TYPE must
- be scalars, or vectors of the same number of elements. If the value
- won't fit in the floating-point type, the results are undefined.
+ be scalars, or vectors of the same number of elements.
``ptrtoint (CST to TYPE)``
Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
``inttoptr (CST to TYPE)``
@@ -8851,8 +8849,9 @@
The '``uitofp``' instruction interprets its operand as an unsigned
integer quantity and converts it to the corresponding floating-point
-value. If the value cannot fit in the floating-point value, the results
-are undefined.
+value. If the value cannot be exactly represented, it is rounded using
+the default rounding mode.
+
Example:
""""""""
@@ -8891,9 +8890,9 @@
""""""""""
The '``sitofp``' instruction interprets its operand as a signed integer
-quantity and converts it to the corresponding floating-point value. If
-the value cannot fit in the floating-point value, the results are
-undefined.
+quantity and converts it to the corresponding floating-point value. If the
+value cannot be exactly represented, it is rounded using the default rounding
+mode.
Example:
""""""""
Index: llvm/trunk/test/Transforms/ConstProp/cast.ll
===================================================================
--- llvm/trunk/test/Transforms/ConstProp/cast.ll
+++ llvm/trunk/test/Transforms/ConstProp/cast.ll
@@ -24,15 +24,15 @@
define float @overflow_uitofp() {
; CHECK-LABEL: @overflow_uitofp(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF0000000000000
;
%i = uitofp i130 400000000000000000000000000000000000000 to float
ret float %i
}
define float @overflow_sitofp() {
; CHECK-LABEL: @overflow_sitofp(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF0000000000000
;
%i = sitofp i130 400000000000000000000000000000000000000 to float
ret float %i
Index: llvm/trunk/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp
+++ llvm/trunk/lib/IR/ConstantFold.cpp
@@ -682,13 +682,8 @@
const APInt &api = CI->getValue();
APFloat apf(DestTy->getFltSemantics(),
APInt::getNullValue(DestTy->getPrimitiveSizeInBits()));
- if (APFloat::opOverflow &
- apf.convertFromAPInt(api, opc==Instruction::SIToFP,
- APFloat::rmNearestTiesToEven)) {
- // Undefined behavior invoked - the destination type can't represent
- // the input constant.
- return UndefValue::get(DestTy);
- }
+ apf.convertFromAPInt(api, opc==Instruction::SIToFP,
+ APFloat::rmNearestTiesToEven);
return ConstantFP::get(V->getContext(), apf);
}
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47807.151435.patch
Type: text/x-patch
Size: 3619 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180614/5119b875/attachment.bin>
More information about the llvm-commits
mailing list