summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAhmed Bougacha <ahmed.bougacha@gmail.com>2015-03-24 23:44:42 +0000
committerAhmed Bougacha <ahmed.bougacha@gmail.com>2015-03-24 23:44:42 +0000
commit6ba3831ebeb147823e7ef0b62a42b558cbafc3da (patch)
tree6673cb14c359846293ea35ffa2e8c99a29d39318 /clang
parent96966c7bf554e693fae804932e1e3ab431d4ea2d (diff)
downloadbcm5719-llvm-6ba3831ebeb147823e7ef0b62a42b558cbafc3da.tar.gz
bcm5719-llvm-6ba3831ebeb147823e7ef0b62a42b558cbafc3da.zip
[CodeGen] Support native half inc/dec amounts.
We previously defaulted to long double, but it's also possible to have a half inc/dec amount, when LangOpts NativeHalfType is set. Currently, that's only true for OpenCL. llvm-svn: 233135
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp7
-rw-r--r--clang/test/CodeGenOpenCL/half.cl8
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 11d10d27c39..16ce69d7999 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1800,9 +1800,14 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
amt = llvm::ConstantFP::get(VMContext,
llvm::APFloat(static_cast<double>(amount)));
else {
+ // Remaining types are either Half or LongDouble. Convert from float.
llvm::APFloat F(static_cast<float>(amount));
bool ignored;
- F.convert(CGF.getTarget().getLongDoubleFormat(),
+ // Don't use getFloatTypeSemantics because Half isn't
+ // necessarily represented using the "half" LLVM type.
+ F.convert(value->getType()->isHalfTy()
+ ? CGF.getTarget().getHalfFormat()
+ : CGF.getTarget().getLongDoubleFormat(),
llvm::APFloat::rmTowardZero, &ignored);
amt = llvm::ConstantFP::get(VMContext, F);
}
diff --git a/clang/test/CodeGenOpenCL/half.cl b/clang/test/CodeGenOpenCL/half.cl
index 7ecae894d03..bd5ae7f6499 100644
--- a/clang/test/CodeGenOpenCL/half.cl
+++ b/clang/test/CodeGenOpenCL/half.cl
@@ -13,3 +13,11 @@ half test()
return z;
// CHECK: half 0xH3260
}
+
+// CHECK-LABEL: @test_inc(half %x)
+// CHECK: [[INC:%.*]] = fadd half %x, 0xH3C00
+// CHECK: ret half [[INC]]
+half test_inc(half x)
+{
+ return ++x;
+}
OpenPOWER on IntegriCloud