r233135 - [CodeGen] Support native half inc/dec amounts.
Ahmed Bougacha
ahmed.bougacha at gmail.com
Tue Mar 24 16:44:42 PDT 2015
Author: ab
Date: Tue Mar 24 18:44:42 2015
New Revision: 233135
URL: http://llvm.org/viewvc/llvm-project?rev=233135&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGenOpenCL/half.cl
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Mar 24 18:44:42 2015
@@ -1800,9 +1800,14 @@ ScalarExprEmitter::EmitScalarPrePostIncD
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);
}
Modified: cfe/trunk/test/CodeGenOpenCL/half.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/half.cl?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/half.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/half.cl Tue Mar 24 18:44:42 2015
@@ -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;
+}
More information about the cfe-commits
mailing list