[llvm-dev] ffp-model=fast ignores #pragma STDC FP_CONTRACT OFF

Kaylor, Andrew via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 27 13:22:13 PDT 2021


I'm not aware of any cases where it isn't possible to honor the pragma. There was a time when the backend didn't have fast-math flags during instruction selection, and so it relied on TargetOptions::FPOpFusion. However, the fast-math flags have been available for several years now. The clang front end generates the correct representation with respect to the pragma (that is, it omits the 'contract' fast-math flag when the pragma turns fp-contract off), but the backend is still looking at the TargetOption::FPOpFusion setting and ignoring the absence of the contract flag. I think this is obviously wrong.

For what it's worth, here is the patch where the DAGCombiner was taught to check the 'contract' fast-math flag: https://reviews.llvm.org/D31169

Note that in this patch, the old check for TargetOptions::FPOpFusion==FPOpFusion::Fast was left (along with TargetOptions::UnsafeFPMath) and used to set a flag, AllowFusionGlobally. I would regard that as a mistake.

-Andy

-----Original Message-----
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Joerg Sonnenberger via llvm-dev
Sent: Tuesday, October 26, 2021 2:26 PM
To: llvm-dev at lists.llvm.org; cfe-dev at lists.llvm.org
Subject: Re: [llvm-dev] ffp-model=fast ignores #pragma STDC FP_CONTRACT OFF

On Tue, Oct 26, 2021 at 04:38:13PM +0000, Kaylor, Andrew via llvm-dev wrote:
> I've brought this up before and I feel very strongly that the pragma 
> should be honored even when fp-contract=fast is used on the command line.

In an ideal world, the pragma should be either honored or result in an explicit compile-time error if it can't be honored. E.g. if the implementation requires the pragma to be specified outside a function, it would be reasonable to error if it should change the state when used inside a function.

Joerg
_______________________________________________
LLVM Developers mailing list
llvm-dev at lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list