[PATCH] D49561: AMDGPU: Try to make isKnownNeverSNan more accurate

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 20 06:38:15 PDT 2018


arsenm added a comment.

In https://reviews.llvm.org/D49561#1169015, @rampitec wrote:

> In https://reviews.llvm.org/D49561#1168791, @arsenm wrote:
>
> > In https://reviews.llvm.org/D49561#1168643, @rampitec wrote:
> >
> > > I would tend to say isKnownNeverSNan here basically tells not that it cannot be sNaN, but rather that we do not care even if it is. At least we should not care if FP exceptions are off.
> >
> >
> > Except that's not true since there can be sNaNs can be loaded, so even if exceptions aren't handled they need to be dealt with
>
>
> Do you mean we shall quiet snans with an fmin/fmax even if exception handling is off? My understanding was different. In fact I thought we can completely ignore them with say fast math.


Yes. My understanding is the exception handling aspect is different from the existence of sNaNs, and also orthogonal to enabling fast math. If exception handling is enabled, operations that can produce sNaNs will, but there can still be sNaNs loaded from memory, constants etc. I think if the function is marked no-nans, we can maybe assume this won't happen? The fast math flags aren't sufficient there because arbitrary operations like a load or function argument don't have an associated flag.

With ieee_mode enabled (which is currently the default) v_min_f32 et. al.  a qNaN is returned if either input is an sNaN. If ieee_mode is off, it returns the non-NaN operand as-if it were a qNaN. I think for what we actually want, ieee_mode is harmful since it requires the library implementation of OpenCL's fmin to insert canonicalizes to quiet the inputs. Since LLVM doesn't properly handle sNaNs anywhere, I think enabling this is a bit pointless. However, whether it's on or not, I think we need to to get sNaN behavior correct at least for this one operation in order to be able to optimize out redundant canonicalizes.


https://reviews.llvm.org/D49561





More information about the llvm-commits mailing list