[RISCV][RV64] Lost zero extension while returning complex floating value
| Bugzilla Link | 42820 |
| Resolution | FIXED |
| Resolved on | Nov 28, 2019 04:06 |
| Version | trunk |
| OS | Linux |
| Attachments | C source test case |
| CC | @asb,@efriedma-quic,@luismarques,@lenary |
Extended Description
Complex floating value for lp64 ABI will be returned by a single register. So the imaginary part will be shift left 32-bits and or with the real part. If the real part didn't do the zero extension to clear the upper bits, the imaginary part may be corrupted by the or operation.
float _Complex complex_add(float _Complex a, float _Complex b) { return a + b; } RealResult = zero_extend(RealA + RealB) ImageResult = ImageA + ImageB Return (RealResult | (ImageResult << 32))
One way to fix the issue is to expand AssertZext to shifts if the value is copied from x10 or x11. But it might be an overkilled method.
Solved by D65497.
Hi Eli,
Thanks for the tips! It seems that we could define shouldSignExtendTypeInLibCall to generate extensions when lowering LibCall. I have created a patch on https://reviews.llvm.org/D65497
It looks like TargetLowering::makeLibCall, called by DAGTypeLegalizer::SoftenFloatRes_FADD, is doing the wrong thing. The result of soft-float libcalls is neither zero-extended nor sign-extended on RISCV, I think.