[ConstantFolding] Fix wrong folding of intrinsic 'convert.from.fp16'.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Thu, 14 May 2015 18:01:48 +0000 (18:01 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Thu, 14 May 2015 18:01:48 +0000 (18:01 +0000)
commit56a5661c60d2a5b9713c3416b15e048d43e34a27
treed1f64520a6f8bb0d25e8846de7c58edb7bd9640e
parentbe4ab8dafe2e1122c14eae7db1223b2180ca899a
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237377 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ConstantFolding.cpp
test/Transforms/ConstProp/convert-from-fp16.ll [new file with mode: 0644]