aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJun Sha (Joshua) <cooper.joshua@linux.alibaba.com>2023-07-28 16:21:24 +0800
committerJun Sha (Joshua) <cooper.joshua@linux.alibaba.com>2023-07-28 16:21:24 +0800
commit62a251f824f63a56563b246035b9bd24078aa98b (patch)
treea03aebe71b225d7aa4a33633ac5b87d5b8b0f39c
parent1195bd48e017bb0f8237dec017e88d23d13ac2a9 (diff)
downloadllvm-62a251f824f63a56563b246035b9bd24078aa98b.zip
llvm-62a251f824f63a56563b246035b9bd24078aa98b.tar.gz
llvm-62a251f824f63a56563b246035b9bd24078aa98b.tar.bz2
[Clang][BFloat16] Upgrade __bf16 by supporting increment/decrement operations
Since __bf16 has been upgraded from a storage-only type to an arithmetic type in https://reviews.llvm.org/rGe62175736551abf40a3410bc246f58e650eb8158, it should support all the basic arithmetic operations like other float types, including increment and decrement. Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D152768
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp6
-rw-r--r--clang/test/Sema/arm-bfloat.cpp2
2 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index fe1a59b..33defb9 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2764,8 +2764,8 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
amt = llvm::ConstantFP::get(VMContext,
llvm::APFloat(static_cast<double>(amount)));
else {
- // Remaining types are Half, LongDouble, __ibm128 or __float128. Convert
- // from float.
+ // Remaining types are Half, Bfloat16, LongDouble, __ibm128 or __float128.
+ // Convert from float.
llvm::APFloat F(static_cast<float>(amount));
bool ignored;
const llvm::fltSemantics *FS;
@@ -2775,6 +2775,8 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
FS = &CGF.getTarget().getFloat128Format();
else if (value->getType()->isHalfTy())
FS = &CGF.getTarget().getHalfFormat();
+ else if (value->getType()->isBFloatTy())
+ FS = &CGF.getTarget().getBFloat16Format();
else if (value->getType()->isPPC_FP128Ty())
FS = &CGF.getTarget().getIbm128Format();
else
diff --git a/clang/test/Sema/arm-bfloat.cpp b/clang/test/Sema/arm-bfloat.cpp
index 34bea9b..6a3eacd 100644
--- a/clang/test/Sema/arm-bfloat.cpp
+++ b/clang/test/Sema/arm-bfloat.cpp
@@ -19,6 +19,8 @@ void test(bool b) {
bf16 - bf16;
bf16 * bf16;
bf16 / bf16;
+ ++bf16;
+ --bf16;
__fp16 fp16;