Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Calls to functions which may change the state of the FP environment may be incorrectly optimized out

pmor
Beginner
903 Views

Sample code:

#include <fenv.h>
#include <math.h>

#if __STDC__ == 1 && __STDC_IEC_559__ == 1

#pragma STDC FENV_ACCESS ON

int main(void)
{
    sin(0.5);
    return fetestexcept(FE_INEXACT) ? 0 : 1;
}

#endif
Options: -std=c11 -Wall -Wextra -fp-model=strict -O2

Generated code:

main:
push rbp #9.1
mov rbp, rsp #9.1
and rsp, -128 #9.1
xor edi, edi #9.1
xor esi, esi #9.1
call __intel_new_feature_proc_init #9.1
mov edi, 32 #11.12
call fetestexcept

Here we see that call sin was incorrectly optimized out.

Tool version: icc 2021.1.2 on Linux on x86-64

0 Kudos
6 Replies
DitiD_Intel
Moderator
862 Views

Hi,

 

Thank you for posting in Intel Communities.

 

O2 optimization will give the maximum optimization. In this case, as you're not using the value of sin(0.5) anywhere else in the code, so it was optimized out, and as a result, you're not able to see it in the assembly code.

 

However, if you use the sin value somewhere in the code, then you will also be able to see the step in the assembly code.

 

I've tried printing the value of sin(0.5) hence, after compilation, I can see the step in the assembly code.

 

For your reference, I've attached screenshots of the source code as well as the assembly code that is being generated after the addition of the print statement.

 

Thanks and Regards,

Ditipriya.

 

 

0 Kudos
pmor
Beginner
845 Views

C11, F.9.1 Global transformations:
> Floating-point arithmetic operations and external function calls may entail side effects which optimization shall honor, at least where the state of the FENV_ACCESS pragma is ‘‘on’’.

0 Kudos
pmor
Beginner
826 Views

Per documentation does Intel C compiler conform to the specifications in the Annex F under -fp-model=strict?

If no, then for which purpose it defines __STDC_IEC_559__ to 1 under -fp-model=strict?

0 Kudos
DitiD_Intel
Moderator
769 Views

Hi,


The original query has been answered and the follow up query is the same as the query in the given URL.


Link : https://community.intel.com/t5/Intel-C-Compiler/STDC-IEC-559-is-defined-to-1-but-SNAN-SNAN-does-not-raise-FE/m-p/1348437/emcs_t/S2h8ZW1haWx8Ym9hcmRfc3Vic2NyaXB0aW9ufEtZMEY2VlhKQVZFR0RYfDEzNDg0Mzd8U1VCU0NSSVBUSU9OU3xoSw#M39574


Can you please let us know if we can go ahead and close the thread?


Thanks and Regards,

Ditipriya.


0 Kudos
DitiD_Intel
Moderator
727 Views

Hi,


We have not heard back from you. This thread will no longer be monitored by Intel. If you need further assistance, please post a new question.


Thanks & Regards,

Ditipriya.



0 Kudos
pmor
Beginner
678 Views

@DitiD_Intel The follow up query (1) is _not_ the same as the query in the given URL (2):
- (1): issue regarding strict floating-point model
- (2): issue regarding non-strict floating-point models
So we need to go ahead and:
1. Answer the question: "Per documentation does Intel C compiler conform to the specifications in the Annex F under -fp-model=strict?"
2. If the answer is "yes", then fix the bug (see title).
3. If the answer is "no", then remove definition of __STDC_IEC_559__ to 1. (Because otherwise it is unclear, for which purpose it defines __STDC_IEC_559__ to 1 under -fp-model=strict.)

0 Kudos
Reply