llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[RISCV][RV64] Lost zero extension while returning complex floating value

Open ShivaChen opened this issue 7 years ago • 3 comments

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.

ShivaChen avatar Jul 30 '19 03:07 ShivaChen

Solved by D65497.

luismarques avatar Nov 28 '19 12:11 luismarques

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

ShivaChen avatar Jul 31 '19 05:07 ShivaChen

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.

efriedma-quic avatar Jul 30 '19 20:07 efriedma-quic