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

Optimization bug causing std::find failure

Mentzer__Stuart
4,336 Views

Hello,

I traced back a problem in an application release build to std::find returning the wrong result on the first call to it with an object not present in the collection but then the correct result on a second call. The attached demo code gives me this output from a release build:

Trigger 00000020F21DFDD0
Trigger 00000020F21DFDE8
 Observer 00000020F21DFDD0
  1
  1
 Observer 00000020F21DFE00
  1                                                              THIS SHOULD BE 0
  0

A debug build or changing /O3 to /O2 or /Qstd=c++17 to c++14 and some other optimization option changes gives the correct results. Pulling the function body into main also gives correct results.

The problem is seen with Intel C++ 19.1.3 and 2020.1.

Environment and build details are in the demo file.

This seems like a serious optimizer bug.

Labels (1)
0 Kudos
1 Solution
ArpitaP_Intel
Moderator
3,370 Views

Hi Stuart,


This issue is fixed in the oneAPI 2021.4 version. Kindly check and let us know if issue still persists.


Thanks!


View solution in original post

0 Kudos
16 Replies
Gopika_Intel
Moderator
4,312 Views

Hi Stuart,

 

Thank you for posting in Intel C++ Compiler forum and providing us with the information about the issue, reproducer code and steps to reproduce the issue. We’re trying to reproduce it from our end. We'll get back to you. Thank you for your patience.

 

Regards

Gopika

 

0 Kudos
Gopika_Intel
Moderator
4,300 Views

Hi Stuart

We executed the reproducer code and we were not able to reproduce the issue. We tried with c++17, c++20 and c++14. We were getting the correct output. The ouput remains correct even if the options /O3 and /O2 are used. The details of our compiler are

>icl --version

Intel(R) C++ Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.1 Build 20201112_000000

Copyright (C) 1985-2020 Intel Corporation. All rights reserved.

We’d also set the compiler version to 19.1.3. We were not able to reproduce the issue.

As you tried in both Intel C++ 19.1.3 and 2020.1, we suggest you to install the latest version of intel C++ Compiler( i.e. 2021) and try running the code again. Please reach out to us if you’re still facing the issue after upgrading.

Regards

Gopika

 

0 Kudos
Mentzer__Stuart
4,287 Views

Hi Gopika,

Thanks for the update. I think we have a real bug here so let's get the details right so the Intel team can reproduce this.

I just reproduced this on a different machine. Did you use the exact combination of flags shown in the demo file? I found that almost any change to those flags eliminates the bug.

icl /nologo /Qstd=c++17 /Qcxx-features /Qvc14.2 /QxHOST /Qansi-alias /DNDEBUG /O3 find_bug.cpp

If you used this then maybe it is hardware (/QxHOST) specific. The 2 systems I reproduced this on are Haswell CPU systems:

  • Intel Core i7-4702HQ 2.20GHz   running Windows 10 1909
  • Intel Core i7-4790K 4.00GHz      running Windows 10 20H2

The problem is present with /QxHOST replaced by /QxHASWELL and /QxSSE4.2 and /QxAVX and /QxCORE-AVX2 on these Haswell CPUs.

I reproduce the issue running Intel C++ 19.1.3 and the OneAPI 2021.1 Build 20201112_000000. There is no later Intel C++ to upgrade to (the 2021.2 update does not appear to include any compiler fixes).

Thanks,
Stuart

 

 

0 Kudos
Viet_H_Intel
Moderator
4,245 Views

I am able to reproduce it and will work with our Developer for a solution.

Thanks,


0 Kudos
Mentzer__Stuart
3,914 Views

FYI this bug is still present in the 2021.2.0 release, at least on top of Visual Studio 16.8.6.

0 Kudos
Viet_H_Intel
Moderator
3,910 Views

I checked the internal bug report, this issue hasn't been fixed yet.

Thanks,


0 Kudos
Viet_H_Intel
Moderator
3,762 Views

 

Can you add /Qhlo0 option as a workaround?

Thanks,

0 Kudos
Mentzer__Stuart
3,693 Views

I can confirm that adding /Qhlo0 eliminates the error for the demo case with icl Version 2021.2.0 Build 20210228_000000.

Since this is an undocumented option can you provide information about what it does and whether it is likely to be better wrt performance than dropping back to /O2 or an earlier CPU /Qx?

Thanks,
Stuart

0 Kudos
Viet_H_Intel
Moderator
3,689 Views

This option turns off some high level optimizations, but it's still better wrt performance than dropping back to /O2 or an earlier CPU /Qx.


Thanks,


0 Kudos
ArpitaP_Intel
Moderator
3,587 Views

Hi Stuart,


The issue is fixed in the oneAPI 2021.3 version. Please let us know if issue still persists.


Thanks!


0 Kudos
Mentzer__Stuart
3,569 Views

Hi ArpitaP,

Unfortunately, the bug is still present in 2021.3.0 Build 20210609_000000 using the command line specified in the sample code. The same work-arounds still work including /Qhlo0 suggested by Viet_H above.

Not sure why the developers would tell you it is fixed when it clearly isn't.

Stuart

0 Kudos
boatvid
Beginner
3,580 Views

how to resolve runtime error ? vidmate w3toys

0 Kudos
ArpitaP_Intel
Moderator
3,536 Views

Hi Stuart,


Apologies for the confusion. I will let you know when the issue is fixed.


Thanks!


0 Kudos
ArpitaP_Intel
Moderator
3,371 Views

Hi Stuart,


This issue is fixed in the oneAPI 2021.4 version. Kindly check and let us know if issue still persists.


Thanks!


0 Kudos
Mentzer__Stuart
3,353 Views

Hi ArpitaP,

 

Yes, I can confirm that this is fixed in oneAPI 2021.4 with VS 2019 16.9.6.

 

Thanks

0 Kudos
ArpitaP_Intel
Moderator
3,335 Views

Hi Stuart,


Thanks for accepting our solution. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks!


0 Kudos
Reply