Open Long5hot opened 6 months ago
@llvm/issue-subscribers-backend-powerpc
Author: Kishan Parmar (Long5hot)
If enabling FP invalid exception, compiling with -mcpu=e500mc -mlong-double-64 -mno-spe
on AIX 32-bit, I got:
0x100006b0 <+208>: fmadd f0,f0,f2,f3
0x100006b4 <+212>: fsub f2,f0,f1
0x100006b8 <+216>: fctiwz f2,f2
0x100006bc <+220>: addi r3,r1,-52
0x100006c0 <+224>: stfiwx f2,0,r3
=> 0x100006c4 <+228>: fctiwz f2,f0. >>>>>>> SIGFPE
(gdb) info registers $f0
f0 2147483712 (raw 0x41e0000008000000)
So because 2147483712 > 2^31, fctiwz
sets VXCVI
that causes FP invalid exception.
When PPC does instruction selection, I don't think the FP invalid exception is considered, i.e. when generating instructions like fctiwz
in convertFPToInt()
, the input range will not be checked to avoid the VXCVI
type exception.
To model these exception behavior in PPC backend seems requiring huge efforts.
Maybe set e500 to use the softfp version instead, as libgcc does?
Set FPSCR register value accordingly (1) FP invalid exc. enable (2) FP overflow exc. enable (3) FP underflow exc. enable (4) FP divide by zero exc. enable
Below test calls __fixunsdfdi from compiler-rt while typecasting from double to unsigned long long.
llvm generates NaN for input 2147483712.000000 on PowerPC-32 e500mc and GNU does not for the same compiler-rt __fixunsdfdi .
clang --target=ppc32 -mcpu=e500mc -mlong-double-64 -mno-spe
Assembly generated by llvm for __fixunsdfdi
Assembly Generated by GNU for the same __fixunsdfdi