[llvm] [AVR] Change `half` to use `softPromoteHalfType` (PR #152783)

Ben Shi via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 9 19:53:18 PDT 2025


benshi001 wrote:

> I just replied at #97975 but I'll give some more details here:
> 
> > However we can not prevent hand writing `double` / `half` in llvm IR, so I am not sure how to deal with that, please let me have a carefully consideration.
> 
> For context, I'm working on Rust's `f16` type, which has the semantics of IEEE binary16, so we _do_ want LLVM's `half` type with those same semantics (promoting to `f32` is not an option). We also don't really need to be concerned about the missing support in libgcc since we bring our own runtime libs to fill in whatever it is missing. I think `_Float16` support is just a case where LLVM is a bit ahead of GCC.
> 
> Currently for AVR, you can use `half` but the generated code is pretty broken, #97981 makes it difficult to implement the intrinsics (just taking a `f16` parameter becomes a recursive libcall). This unbreaks that and at least lets us build the intrinsics to experiment more.
> 
> > So I think the best way is also attributing half type to float32, to fit avr-gcc-7.3 (and its libgcc) which is the main stream version in real production environment.
> 
> You are talking about the Clang frontend here right, something like C23 `_Float16x`? Since LLVM's `half` is fixed-size, as is Rust and Zig's `f16` and C23's `_Float16` (if that ever winds up supported).

I saw pairs of 
```
; CHECK-NEXT:    rcall __truncsfhf2
; CHECK-NEXT:    rcall __extendhfsf2
```
is generated, though it is less efficient, it is better than broken.

https://github.com/llvm/llvm-project/pull/152783


More information about the llvm-commits mailing list