diff options
author | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2015-05-14 18:01:48 +0000 |
---|---|---|
committer | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2015-05-14 18:01:48 +0000 |
commit | 2905999c22a0b0b21499374ee6e07a20d0f14a27 (patch) | |
tree | 8b185f244b5e54315d91586ea76665c60f4e17db /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 42e1e66e55bd297a2d16d0ff5f476f79ad3f08f6 (diff) | |
download | bcm5719-llvm-2905999c22a0b0b21499374ee6e07a20d0f14a27.tar.gz bcm5719-llvm-2905999c22a0b0b21499374ee6e07a20d0f14a27.zip |
[ConstantFolding] Fix wrong folding of intrinsic 'convert.from.fp16'.
Function 'ConstantFoldScalarCall' (in ConstantFolding.cpp) works under the
wrong assumption that a call to 'convert.from.fp16' returns a value of
type 'float'.
However, intrinsic 'convert.from.fp16' can be overloaded; for example, we
can call 'convert.from.fp16.f64' to convert from half to double; etc.
Before this patch, the following example would have triggered an assertion
failure in opt (with -constprop):
```
define double @foo() {
entry:
%0 = call double @llvm.convert.from.fp16.f64(i16 0)
ret double %0
}
```
This patch fixes the problem in ConstantFolding.cpp. When folding a call to
convert.from.fp16, we perform a different kind of conversion based on the call
return type.
Added test 'Transform/ConstProp/convert-from-fp16.ll'.
Differential Revision: http://reviews.llvm.org/D9771
llvm-svn: 237377
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 85a66331108..2f4c6a92f9a 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1543,8 +1543,8 @@ static Constant *ConstantFoldScalarCall(StringRef Name, unsigned IntrinsicID, APFloat Val(APFloat::IEEEhalf, Op->getValue()); bool lost = false; - APFloat::opStatus status = - Val.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &lost); + APFloat::opStatus status = Val.convert( + Ty->getFltSemantics(), APFloat::rmNearestTiesToEven, &lost); // Conversion is always precise. (void)status; |