<div dir="ltr"><div>Hi Arthur,<br></div><div dir="ltr"><br></div><div dir="ltr">On Mon, 20 Apr 2020 at 17:30, Arthur O'Dwyer via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><br><div>- Personally I have never understood the difference between -target, -march, -mcpu, and -mtune (particularly -march and -mtune). There are a lot of blog posts out there (e.g. <a href="https://lemire.me/blog/2018/07/25/it-is-more-complicated-than-i-thought-mtune-march-in-gcc/" target="_blank">https://lemire.me/blog/2018/07/25/it-is-more-complicated-than-i-thought-mtune-march-in-gcc/</a> <a href="http://sdf.org/~riley/blog/2014/10/30/march-mtune/" target="_blank">http://sdf.org/~riley/blog/2014/10/30/march-mtune/</a> ) indicating that I'm not alone.  (Anyone got a really good resource on this topic?)</div></div></div></div></div></div></blockquote><div><br></div><div>from the GCC manual for the x86 target ( <a href="https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/x86-Options.html#x86-Options">https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/x86-Options.html#x86-Options</a> ):</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><dt><code>-march=<var>cpu-type</var></code></dt>
<dd><a name="index-march-14"></a>
<p>Generate instructions for the machine type <var>cpu-type</var>.  In contrast to
<samp>-mtune=<var>cpu-type</var></samp>, which merely tunes the generated code 
for the specified <var>cpu-type</var>, <samp>-march=<var>cpu-type</var></samp> allows GCC
to generate code that may not run at all on processors other than the one
indicated.  Specifying <samp>-march=<var>cpu-type</var></samp> implies 
<samp>-mtune=<var>cpu-type</var></samp>.<br></p></dd></div><div><dt><br><code></code></dt><dt><code>-mtune=<var>cpu-type</var></code></dt>
<dd><a name="index-mtune-16"></a>
<p>Tune to <var>cpu-type</var> everything applicable about the generated code, except
for the ABI and the set of available instructions.  
While picking a specific <var>cpu-type</var> schedules things appropriately
for that particular chip, the compiler does not generate any code that
cannot run on the default machine type unless you use a
<samp>-march=<var>cpu-type</var></samp> option.
For example, if GCC is configured for i686-pc-linux-gnu
then <samp>-mtune=pentium4</samp> generates code that is tuned for Pentium 4
but still runs on i686 machines. <br></p></dd><dt><br><code></code></dt><dt><code>-mcpu=<var>cpu-type</var></code></dt>
<dd><a name="index-mcpu-15"></a>
<p>A deprecated synonym for <samp>-mtune</samp>.
</p></dd></div></div></blockquote><div><br></div><div>So, -march tells the compiler what instructions it can use, and thus sets a kind of minimum requirements for running the generated binary; while -mtune directs optimisation choices, but does not impact which CPUs can run the binary. </div><div><br></div><div>Looking at the documentation for other targets like ARM and RISC-V, it seems that the behaviour of -march and -mtune is consistent across them, while in some cases -mcpu may specify additional flags.<br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div>- It sounds like -mtune's behavior is not "falsifiable"; it can never produce "wrong" code; it's purely an optimization option, like -O2. </div></div></div></div></div></div></blockquote><div><br></div><div>Indeed.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div>So there is no practical difference, but there may be a psychological difference, between saying "Clang permanently treats -mtune as a no-op" versus "Clang has a remarkably low <i><b>quality of implementation</b></i> for -mtune, and has no immediate plans to either improve or regress it."</div></div></div></div></div></div></blockquote><div><br></div><div>True... I'd document it as a "no-op" :-)</div><div><br></div><div>Ciao,<br></div><div>.Andrea<br></div><br></div></div>