Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
7731 Discussions

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

pmor
Beginner
589 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
548 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.

 

 

pmor
Beginner
531 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’’.

pmor
Beginner
512 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?

DitiD_Intel
Moderator
455 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-...


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


Thanks and Regards,

Ditipriya.


DitiD_Intel
Moderator
413 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.



pmor
Beginner
364 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.)

Reply