-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Description
As https://gcc.gnu.org/wiki/avr-gcc, double type is attributed to float32 on avr-gcc-7.3, since libgcc-7.3 does not contains infrastructure for float64 type. And clang follows this way. However clang should also treats float16 as float32.
void qww(double *p ) {
*p = p[1] + 1.0;
}
is compiled to the following IR file by clang
; Function Attrs: noinline nounwind optnone
define dso_local void @qww(ptr noundef %p) addrspace(1) #0 {
entry:
%p.addr = alloca ptr, align 1
store ptr %p, ptr %p.addr, align 1
%0 = load ptr, ptr %p.addr, align 1
%arrayidx = getelementptr inbounds float, ptr %0, i16 1
%1 = load float, ptr %arrayidx, align 1
%add = fadd float %1, 1.000000e+00
%2 = load ptr, ptr %p.addr, align 1
store float %add, ptr %2, align 1
ret void
}
However clang can not handle float16 type correctly, it should also treats fp16 as float32.
fp16 operations are miscompiled.
void qww(__fp16 *p ) {
*p = p[1] + 1.0;
}
; Function Attrs: noinline nounwind optnone
define dso_local void @qww(ptr noundef %p) addrspace(1) #0 {
entry:
%p.addr = alloca ptr, align 1
store ptr %p, ptr %p.addr, align 1
%0 = load ptr, ptr %p.addr, align 1
%arrayidx = getelementptr inbounds i16, ptr %0, i16 1
%1 = load i16, ptr %arrayidx, align 1
%2 = call addrspace(1) float @llvm.convert.from.fp16.f32(i16 %1)
%add = fadd float %2, 1.000000e+00
%3 = call addrspace(1) i16 @llvm.convert.to.fp16.f32(float %add)
%4 = load ptr, ptr %p.addr, align 1
store i16 %3, ptr %4, align 1
ret void
}