[llvm-dev] [FPEnv] undef and constrained intrinsics?

Sanjay Patel via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 21 06:15:45 PDT 2021


Can we use the regular FP instructions (fadd, fmul, etc.) as a model?

If both operands to any of the binops are undef, then the result is undef.
So for the corresponding constrained intrinsic, if both operands are undef,
the result is undef and the exception state is also undef:

  %r = call float @llvm.experimental.constrained.fadd.f32(float undef,
float undef, metadata !"round.dynamic", metadata !"fpexcept.strict")
  -->
  %r = undef

  %r = call float @llvm.experimental.constrained.fadd.f32(float undef,
float undef, metadata !"round.dynamic", metadata !"fpexcept.maytrap")
  -->
  %r = undef


If one operand is undef and the other is regular value, assume that the
undef value takes on some encoding of SNaN:

  %r = call float @llvm.experimental.constrained.fadd.f32(float undef,
float %x, metadata !"round.dynamic", metadata !"fpexcept.strict")
  -->
  %r = call float @llvm.experimental.constrained.fadd.f32(float SNaN, float
%x, metadata !"round.dynamic", metadata !"fpexcept.strict") ; raise invalid
op exception
  (%r could be folded to QNaN here, but we can't get rid of the call, so
don't bother?)

  %r = call float @llvm.experimental.constrained.fadd.f32(float undef,
float %x, metadata !"round.dynamic", metadata !"fpexcept.maytrap")
  -->
  %r = QNaN ; exception state does not have to be preserved

Does that match the proposed behavior in https://reviews.llvm.org/D102673 (cc
@sepavloff)?

We could go further (potentially reduce to poison) if we have
fast-math-flags on the calls -- just as we partially do with the regular
instructions -- but it probably doesn't matter much to real code.


On Fri, Jul 9, 2021 at 12:06 PM Kevin Neal via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> How should the constrained FP intrinsics behave when called with an
> operand that is “undef” and the FP environment is _*not*_ the default
> environment? I’m specifically working in the middle end passes if it
> matters. Let me start with the assumption that the rounding mode is not
> relevant. That still leaves the exception handling as a factor:
>
> With “fpexcept.maytrap” we are allowed to drop instructions that could or
> would cause a trap at run-time. Does this imply we can fold the entire
> instruction to a new undef?
>
> With “fpexcept.strict” we are _*not*_ allowed to lose or reorder traps.
> So how does that affect undef? What happens in the backend? Perhaps the
> middle end should leave the instruction with the undef and let the backend
> do something reasonable?
>
> The “maytrap” case is the one I’m most interested in. An earlier version
> of D103169 would fold away undef constrained intrinsics in the maytrap
> case. This was removed so it could be handled without affecting the rest of
> the patch I believe.
>
> Opinions?
> --
> Kevin P. Neal
> SAS/C and SAS/C++ Compiler
> Compute Services
> SAS Institute, Inc.
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210721/3282c275/attachment.html>


More information about the llvm-dev mailing list