I am looking at the documenation of the compiler flag "-qopt-prefetch" and I am wondering two things:
- Is there a drawback to always have it on? i.e. could the compiler make bad pre-fetching choices and create slower code if I switch it on?
- Is that flag part of any of the meta-flags like -O2?
Thanks for your advice!
Thank you for reaching out to us.
Prefetching optimization will totally depend on your use-case. Based on your use-case you will experience the benefits and drawbacks of it.
Suppose your use-case has some small array streams, small irregular memory address patterns, and L1 cache miss reduction operations, then there will be a more chance of positive impact using Prefetching.
Because arrays and some recursive data structure accesses can be easily predicted and will have a positive impact over software prefetching. However, data structures like hashing are much harder to prefetch effectively.
Or Suppose in your use-case when the number of instructions in a loop is extremely small, it can be challenging to insert software prefetching instructions to provide timely prefetching requests because there are no enough computations between prefetching instructions.
So depending on your use-case you can take the advantage of prefetching, you can also set the levels of prefetching (-qopt-prefetch[=n]) or can disable it (-qno-opt-prefetch), depending on the scenario or you can also add the prefetching intrinsic (_mm_prefetch()) if you fill compiler is creating overhead while prefetching.
For more details please refer below link:
The O2 optimization may enable data prefetching depending on the application. Whereas if you specify O3 level optimization, it will enable more aggressive prefetching.
Hope the above details will give you insights about the use of prefetch.