The priority of -fno-fast-math regarding complex number calculations

The situation seems complex, so I’d like to clarify things to ensure my understanding.

GCC Behavior

GCC has three options related to complex number calculations:

  • -f[no-]fast-math
  • -f[no-]cx-limited-range
  • -f[no-]cx-fortran-rules

My understanding is that these options follow these rules:

  1. -f[no-]cx-fortran-rules has the highest priority.
  2. -f[no-]cx-limited-range and -ffast-math have the same priority.
  3. -fno-fast-math only disables -ffast-math.

Based on these GCC rules, the behavior is as follows:

GCC Rule Example Option for Use in Complex Number Calculations
1 -fcx-fortran-rules -fcx-limited-range -ffast-math -fcx-fortran-rules
-fno-cx-fortran-rules -fcx-limited-range -ffast-math -fno-cx-fortran-rules
2 -ffast-math -fno-cx-limited-range -fno-cx-limited-range
-fno-cx-limited-range -ffast-math -ffast-math
3 -ffast-math -fno-fast-math No enabled option for complex number calclations
-fcx-limited-range -fno-fast-math -fcx-limited-range
-ffast-math -fcx-limited-range -fno-fast-math -fcx-limited-range

Current Clang Behavior

Clang has the following five options related to complex number calculations:

  • -f[no-]fast-math
  • -f[no-]cx-limited-range
  • -f[no-]cx-fortran-rules
  • -ffp-model=[strict|precise|fast|aggressive]
  • -fcomplex-arithmetic=[full|improved|promoted|basic]

And the Clang rules seem to be:

  1. Except for -fno-fast-math, the last specified option is enabled.
  2. -fno-fast-mathdoes nothing regarding the configuration of complex number calculations. This is a bug.

In other words, Clang’s current behavior is not the same as GCC’s for the GCC options. Also, the relationship between the GCC and Clang options is ambiguous.

Proposal

To clarify the relationship between these options, how about the following rules, for example?

  • Proposed Clang Rules:
  1. If only GCC options are specified, follow the GCC rules.
  2. If both GCC’s enabling options and Clang-specific options are specified, the last specified option is enabled.
  3. GCC’s disabling options only disable GCC’s enabling options. That is, they do not disable Clang-specific options.
  4. -fno-fast-math disables the complex number calculation setting of -ffast-math and -ffp-model=fast,aggressive. That is, it does not disable -ffp-model=precise,strict, -fcomplex-arithmetic=*, or -fcx-*.

Given the rules above, Clang will behave as follows:

Clang Rule Example Option for Use in Complex Number Calculations
1 -fcx-limited-range -fcx-fortran-rules -ffast-math -fcx-fortran-rules
-fno-cx-limited-range -ffast-math -ffast-math
-ffast-math -fcx-limited-range -fno-fast-math -fcx-limited-range
2 -fcx-fortran-rules -ffp-model=fast -ffp-model=fast
-fcx-limited-range -fcomplex-arithmetic=full -fcomplex-arithmetic=full
-ffp-model=fast -fcx-limited-range -fcx-limited-range
-fcomplex-arithmetic=full -fcx-fortran-rules -fcx-fortran-rules
-fcomplex-arithmetic=full -ffast-math -ffast-math
3 -fcomplex-arithmetic=basic -fno-cx-limited-range -fcomplex-arithmetic=basic
-ffp-model=aggressive -fcx-fortran-rules -fno-cx-fortran-rules -ffp-model=aggressive
4 -ffast-math -ffp-model=fast -fno-fast-math No enabled option for complex number calclations
-ffast-math -fcomplex-arithmetic=basic -fno-fast-math -fcomplex-arithmetic=basic
-fcomplex-arithmetic=basic -ffp-model=presice -fno-fast-math -ffp-model=presice
-fcomplex-arithmetic=basic -ffp-model=fast -fno-fast-math -fcomplex-arithmetic=basic
-fcomplex-arithmetic=improved -fcx-limited-range -ffp-model=fast -fno-fast-math -fcx-limited-range

Even with the above rules, there are two concerns:

  1. When both GCC and Clang-specific options are specified, the GCC options will no longer satisfy the GCC rules. For example, if -fcomplex-arithmetic=full -fcx-fortran-rules -fcx-limited-range is specified, according to the proposed Clang rule 2, the last specified option, -fcx-limited-range, will be enabled. However, if -fcx-fortran-rules -fcx-limited-range is specified, -fcx-fortran-rules will be enabled based on GCC rule 1. Would this difference be acceptable?
  2. -fno-fast-math may cause more unstable complex number calculations. For example, if -fcx-limited-range -ffp-model=fast -fno-fast-math is specified, -fcx-limited-range implies -fcomplex-arithmetic=basic and -ffp-model=fast implies -fcomplex-arithmetic=promoted, and the latter promoted is stricter. However, based on the proposed Clang rule 4, the complex number setting of -ffp-model=fast is disabled by -fno-fast-math, basic implied by -fcx-limited-range is enabled. Is this also acceptable?

Any opinions or suggestions would be greatly appreciated. In particular, the GCC behavior is based on my understanding, so I may be wrong. Also, please comment if anything is unclear.