Fast-math flags in constant expressions

Hi,

I'm wondering why lib/AsmParser/LLParser handles fast-math flags in the
following IR:

    ...
    %val = fmul nnan double 1.0, 1.0
    ...

but doesn't allow any flags if "fmul" is inside "phi":

    ...
    %val = phi double [ fmul (double 1.0, double 1.0), %cond.true ],
                      [ fmul (double 1.0, double 1.0), %cond.false ]
    ...

LLParser::ParseValID(...) could call EatFastMathFlagsIfPresent() to
handle fast-math flags, but it doesn't. Is this intended or a bug?

Regards,
Sergey

Doesn't look like a bug, more like a limitation of constant expressions
as llvm::BinaryConstantExpr doesn't have FastMastFlags.

Out of curiosity, how would you envision fast-math flags interacting with constant expressions? Off the top of my head, I can’t think of any flags that would be relevant if the expression can just be constant-folded away at full precision anyways.

Out of curiosity, how would you envision fast-math flags
interacting with constant expressions?

They could prevent constant-folding when it leads to loosing
floating-point exceptions at runtime.

Off the top of my head, I can’t think of any flags that would be
relevant if the expression can just be constant-folded away at
full precision anyways.

I'm adding them. It worked fine with function attributes, but replacing
attributes with instruction flags revealed this inconvenience. At the
end it doesn't seem to be an issue as front-end can just emit normal
instructions rather than constant expression when FPEnv access is
enabled.

That's the opposite of what fast math flags do.

If you want to solve that problem, I believe you want to prevent the folding of floating point instructions into constant expressions. The direction you're going seems like a pretty major violation of the intended functionality of constant expressions.

-Owen

That's the opposite of what fast math flags do.

Well, still quite close. Function arguments turned out to be a bad
choice, so Hal suggested using fast-math flags instead. I guess there
isn't many other options.

If you want to solve that problem, I believe you want to prevent the
folding of floating point instructions into constant expressions.

Yes, that's what I did at the end. Probably wasn't clear enough in my
previous email.

The direction you're going seems like a pretty major violation of the
intended functionality of constant expressions.

If you're talking about adding fast-math flags to constant expressions,
then I'm not going to try that. It just that Language Reference doesn't
note this difference for binary operations inside/outside constant
expressions (maybe I didn't find it, but I was looking there).