]> granicus.if.org Git - clang/commitdiff
[CodeGen] Support native half inc/dec amounts.
authorAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 24 Mar 2015 23:44:42 +0000 (23:44 +0000)
committerAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 24 Mar 2015 23:44:42 +0000 (23:44 +0000)
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

lib/CodeGen/CGExprScalar.cpp
test/CodeGenOpenCL/half.cl

index 11d10d27c39811b569168f82c58c5f0cc356412a..16ce69d7999a005407ce3cf15a1c33685d4ee614 100644 (file)
@@ -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);
     }
index 7ecae894d03dc4f54fba36e1005a06c9990669eb..bd5ae7f649900ce6b352172a5626bc634d1bf8bf 100644 (file)
@@ -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;
+}