[CIR] Upstream missing support for floating point operations
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
### Overview
Upstream code from the incubator project to replace errorNYI calls in the
CIR codegen implementation related to increment/decrement and literal
emission for non-standard numeric types:
- **Half-precision inc/dec**: promoting `__fp16` / `_Float16` to `float`,
performing the increment/decrement, then demoting back to half
- **Other floating-point type inc/dec**: handling `long double`, `__bf16`, and
`_Float16` by constructing an `llvm::APFloat` with the increment value in the
target's float semantics and emitting `createBinop(..., BinOpKind::Add, ...)`
- **Fixed-point literals**: emitting fixed-point literal values as constant
integers via `Builder.getConstAPInt()`
Upstream NYI locations:
- `CIRGenExprScalar.cpp` — `emitScalarPrePostIncDec`: half-precision inc/dec
without native half type
- `CIRGenExprScalar.cpp` — `emitScalarPrePostIncDec`: other floating-point type
inc/dec (LongDouble, BF16, etc.)
- `CIRGenExprScalar.cpp` — `VisitFixedPointLiteral`: fixed-point literal
emission
### Suggested minimal test case
```c
// Half-precision increment
void test_fp16_inc(__fp16 *p) {
(*p)++;
}
// Long double increment
void test_long_double_inc(long double *p) {
++(*p);
}
// BFloat16 increment
void test_bf16_inc(__bf16 *p) {
(*p)++;
}
// Fixed-point literal (requires -ffixed-point)
// _Accum test_fixed_point() {
// return 1.5k;
// }
```
### Existing incubator tests
- `clang/test/CIR/CodeGen/fp16-ops.c`
- `clang/test/CIR/CodeGen/float16-ops.c`
- `clang/test/CIR/CodeGen/bf16-ops.c`
Contributor guide
Assessment
This issue has not been assessed yet.