Skip to content

Commit

Permalink
[Clang][BFloat16] Upgrade __bf16 by supporting increment/decrement op…
Browse files Browse the repository at this point in the history
…erations

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
  • Loading branch information
joshua-arch1 committed Jul 28, 2023
1 parent 1195bd4 commit 62a251f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clang/lib/CodeGen/CGExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Sema/arm-bfloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void test(bool b) {
bf16 - bf16;
bf16 * bf16;
bf16 / bf16;
++bf16;
--bf16;

__fp16 fp16;

Expand Down

0 comments on commit 62a251f

Please sign in to comment.