Except for custom floating point types x86_fp80 and ppc_fp128,
expand Y = FNEG(X) to Y = X ^ sign mask to avoid library call.
Using bitwise operation can improve code size and performance.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
For the cases it does not transform, we still do not need to make lib calls.
Try:
llc -mtriple=arm-eabi -float-abi=soft legalize-fneg.ll
It generates:
.save {r4, lr} push {r4, lr} ldr r1, [r1] mov r4, r0 mov r0, #-2147483648 bl __aeabi_fsub str r0, [r4] pop {r4, lr} mov pc, lr
Without this patch is the fneg instruction getting turned into a subtraction instruction? I hope not on any platform!
Without the patch, the fneg use in the given test case becomes a sub lib call in the targets I checked when using soft abi (riscv, arm)
DAGCombiner::visitFNEG is transforming fneg(bitconvert(x)) to bitwise operation. So for other patterns, we end up with a lib call which is wasteful.
I also need someone to confirm whether for x86 and ppc FP types it is valid to use bitwise operation. The patch now excludes these formats.
LGTM
Without this patch is the fneg instruction getting turned into a subtraction instruction? I hope not on any platform!
Without this patch we generate calls to __subsf3 etc. There's also equivalent code in LegalizeDAG, but I think in practice it doesn't get used because targets with floating-point support generally have a native fneg instruction.