Page MenuHomePhabricator

Add denormal-fp-math attribute for f16
AbandonedPublic

Authored by dcandler on Jul 7 2022, 8:53 AM.

Details

Summary

Denormal flushing behavior is currently controlled with the
denormal-fp-math attribute, with a denormal-fp-math-f32 variant for
targets such as AMDGPU where f32 denormals are controlled separately
from f16/f64. However there are other targets such as Arm (and I
think x86) where f16 denormals can be distinct from f32/f64. As the
attributes are now used for constant folding, this can lead to
incorrect folded values for half precision floats on those targets.

This patch adds a denormal-fp-math-f16 attribute, which functions
identically to denormal-fp-math-f32, but overrides the denormal
handling mode for f16 only. Constant folding tests have been
expanded to include half floats, and check both f16 and f32
variants of the attribute.

Diff Detail

Event Timeline

dcandler created this revision.Jul 7 2022, 8:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2022, 8:53 AM
dcandler requested review of this revision.Jul 7 2022, 8:53 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 7 2022, 8:53 AM
arsenm added a comment.Jul 7 2022, 9:11 AM

Missing ARM changes that demonstrate the use of the control?

There are currently no Arm specific changes, this is just being able to more accurately describe the floating point environment via attributes in the case where singles and doubles should be flushed, but not halves.

With three precisions to control, an alternative may be to specify them individually (denormal-fp-math-f64, denormal-fp-math-f32 and denormal-fp-math-f16) so that one doesn't override another, but that would be a much larger and more intrusive change.

There are currently no Arm specific changes, this is just being able to more accurately describe the floating point environment via attributes in the case where singles and doubles should be flushed, but not halves.

But presumably this corresponds with a directive in the assembly output needed to get a consistent FP mode at start. e.g. ARMAsmPrinter has checks for denormal-fp-math and emits something from it. I would expect a similar check and corresponding test if you can change these separately

Reverse ping

dcandler abandoned this revision.Nov 2 2022, 10:01 AM

Sorry for the quiet on this. I'm going to abandon this for the moment, as what I eventually found was that there was some ambiguity in the ARM ABI regarding half-floats which would be better to address first, so that the attributes can map directly. There is currently only one ARM build attribute for denormals which reads as though it affects all precisions, but may not have been updated after half-float support was added. Since that maps to denormal-fp-math, which also controls all precisions, both may need splitting rather than just the function level attribute.