[clang] 62a251f - [Clang][BFloat16] Upgrade __bf16 by supporting increment/decrement operations
Jun Sha via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 28 01:21:02 PDT 2023
Author: Jun Sha (Joshua)
Date: 2023-07-28T16:21:24+08:00
New Revision: 62a251f824f63a56563b246035b9bd24078aa98b
URL: https://github.com/llvm/llvm-project/commit/62a251f824f63a56563b246035b9bd24078aa98b
DIFF: https://github.com/llvm/llvm-project/commit/62a251f824f63a56563b246035b9bd24078aa98b.diff
LOG: [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
Added:
Modified:
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/Sema/arm-bfloat.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index fe1a59b21f3801..33defb9c87e90f 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 34bea9b2ec9725..6a3eacd331d5c4 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;
More information about the cfe-commits
mailing list