- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is sort of a trick to get an optimizing compiler to prove an interesting property of some code; we insert a call to an nonexistent extern function along the code path we want to have proven is impossible. If the optimizer fails to prove that the code path is never taken, the code fails to link. I tried to use this in a Vec3/Point implementation and was surprised to see that icc doesn't manage to prove the extern function is never called (clang and gcc do manage this). The runtime performance of this code isn't really the point, what I'd like is the optimizer's proof.
https://godbolt.org/z/SqPBZ_
- Tags:
- CC++
- Development Tools
- Intel® C++ Compiler
- Intel® Parallel Studio XE
- Intel® System Studio
- Optimization
- Parallel Computing
- Vectorization
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the optimizer fails to prove that the code path is never taken, the code fails to link.
Can you provide us a test case to show this happens?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I provided a godbolt link in my original post, which is a case I've run into. Is that insufficient? I'm happy to whip up something else if it doesn't fulfill your requirements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would be helpful if you could provide us code that fails to link.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#include <vector> extern double optimization_failed(); struct Vec3 { double x, y, z; double operator[](int index) const { switch (index) { case 0: return x; case 1: return y; case 2: return z; default: return optimization_failed(); } } }; std::vector<Vec3> r; std::vector<double> w; bool point_is_in_cell(Vec3 const point, int _i_cell) { for (int i = 0; i < 3; ++i) if (point < r[_i_cell] || point >= r[_i_cell] + w[_i_cell]) return false; return true; } int main() { w = std::vector<double>(1, 1.); r = std::vector<Vec3>(1, Vec3{1., 2., 3.}); return point_is_in_cell(Vec3{0., 0., 0.}, 0); }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank for the test case. I'll take a look and get back to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've reported this case to the compiler team. An internal report number is: CMPLRIL0-31953

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page