From: Ahmed Bougacha Date: Tue, 24 Mar 2015 23:44:42 +0000 (+0000) Subject: [CodeGen] Support native half inc/dec amounts. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=55aee062522b8294fae619a92a1624ce989ceb96;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233135 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 11d10d27c3..16ce69d799 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -1800,9 +1800,14 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, amt = llvm::ConstantFP::get(VMContext, llvm::APFloat(static_cast(amount))); else { + // Remaining types are either Half or LongDouble. Convert from float. llvm::APFloat F(static_cast(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/test/CodeGenOpenCL/half.cl b/test/CodeGenOpenCL/half.cl index 7ecae894d0..bd5ae7f649 100644 --- a/test/CodeGenOpenCL/half.cl +++ b/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; +}