This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fix the neutral element in vector 'fadd' reductions
ClosedPublic

Authored by frasercrmck on Jul 13 2021, 9:22 AM.

Details

Summary

Using positive zero as the neutral element in 'fadd' reductions, while
it generates better code, is incorrect. The correct neutral element is
negative zero: 0.0 + -0.0 = 0.0, whereas -0.0 + -0.0 = -0.0.

There are perhaps more optimal lowerings of negative zero avoiding
constant-pool loads which could be left as future work.

Diff Detail

Event Timeline

frasercrmck created this revision.Jul 13 2021, 9:22 AM
frasercrmck requested review of this revision.Jul 13 2021, 9:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2021, 9:22 AM
This revision is now accepted and ready to land.Jul 13 2021, 10:07 AM

Presumably something like:

fmv.[hwd].x freg, zero
fsgnjn.[hsd] freg, freg, freg

(leaving D as using a constant pool on RV32) would do the trick?

This revision was landed with ongoing or failed builds.Jul 14 2021, 2:27 AM
This revision was automatically updated to reflect the committed changes.

Presumably something like:

fmv.[hwd].x freg, zero
fsgnjn.[hsd] freg, freg, freg

(leaving D as using a constant pool on RV32) would do the trick?

Sounds good, yeah. I'll put it on my list but if anyone else feels like taking it on, be my guest.