[PATCH] D136080: [flang] Add -ffp-contract option processing

Tom Eccles via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 20 03:19:41 PDT 2022


tblah added inline comments.


================
Comment at: flang/include/flang/Frontend/LangOptions.h:29
+
+    // Enable the floating point pragma
+    FPM_On,
----------------
vzakhari wrote:
> tblah wrote:
> > awarzynski wrote:
> > > What are these pragmas? Perhaps you can add a test that would include them?
> > I copied this comment from clang. I believe the pragma is 
> > ```
> > #pragma clang fp contract(fast)
> > ```
> > 
> > See https://clang.llvm.org/docs/LanguageExtensions.html#extensions-to-specify-floating-point-flags
> > 
> > This patch only adds support for argument processing, so I can't test for the pragmas.
> I do not think we should blindly copy this from clang.  I believe `-ffp-contract=on`  is there to do the contraction complying to the language standard - but Fortran standard says nothing about contraction.  I am also not aware about a Fortran compiler that supports directives related to contraction, so `fast-honor-pragmas` does not seem to be applicable as well.  Basically, we end up with just `off` and `fast`.
> 
> Now, it may be reasonable to support the same `-ffp-contract=` arguments so that users can apply the same options sets for C/C++ and Fortran compilations.  If we want to do this, we need to map `on` and `fast-honor-pragmas` to something, e.g. `fast`.  A driver warning (not an error) may be useful to make the option's behavior clear when `on` and `fast-honor-pragmas` are passed.
>From the clang help text:
```
Form fused FP ops (e.g. FMAs):
fast (fuses across statements disregarding pragmas)
| on (only fuses in the same statement unless dictated by pragmas)
| off (never fuses)
Default is 'on'
```

So if we removed `on` and set the default to `off` we would no longer fuse within the same statement by default.

Classic-flang seems to support `on`, `off` and `fast`: https://github.com/flang-compiler/flang/blob/master/test/llvm_ir_correct/fma.f90


================
Comment at: flang/test/Driver/driver-help-hidden.f90:34
 ! CHECK-NEXT: Use <value> as character line width in fixed mode
+! CHECK-NEXT: -ffp-contract=<value> Form fused FP ops (e.g. FMAs): fast (fuses across statements disregarding pragmas) | on (only fuses in the same statement unless dictated by pragmas) | off (never fuses) | fast-honor-pragmas (fuses across statements unless diectated by pragmas). Default is 'fast' for CUDA, 'fast-honor-pragmas' for HIP, and 'on' otherwise.
 ! CHECK-NEXT: -ffree-form            Process source files in free form
----------------
vzakhari wrote:
> Is it easy to emit a different help message for Flang to say that there are only two modes for Fortran?
@awarzynski tells me there is no way to do this short of having separate `Options.td` for flang and clang. Once we have settled on which arguments to support, I will update the shared help text to mention flang.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136080/new/

https://reviews.llvm.org/D136080



More information about the cfe-commits mailing list