<div dir="ltr">One data point. I ran check-llvm with a tweaked <b>SelectionDAG::getMemcpy</b> that always sets <b>isVol</b> to false.<div>Only one test fails <a href="https://github.com/llvm-project/llvm-project/blob/ea0411ed880b5b5ae9eea03d64dc0ddb4440259b/llvm/test/CodeGen/X86/stack-align.ll#L69">llvm/test/CodeGen/X86/stack-align.ll</a> and I think it's a false positive.</div><div><br></div><div>----</div><div>Before<br></div><div><font face="courier new, monospace">_test5: ## @test5<br>## %bb.0:<br> pushl %ebp<br> movl %esp, %ebp<br> andl $-16, %esp<br><b> subl $32, %esp</b><br><b> movsd 8(%ebp), %xmm0 ## xmm0 = mem[0],zero</b><br><b> movsd 16(%ebp), %xmm1 ## xmm1 = mem[0],zero</b><br><b> movsd %xmm1, 16(%esp)</b><br><b> movsd %xmm0, 8(%esp)</b><br> movl %ebp, %esp<br> popl %ebp<br> retl $16<br> ## -- End function<br></font></div>After<div><font face="courier new, monospace">_test5: ## @test5<br>## %bb.0:<br> pushl %ebp<br> movl %esp, %ebp<br> andl $-16, %esp<br> movl %ebp, %esp<br> popl %ebp<br> retl $16<br> ## -- End function</font><br></div><div><br></div><div><div>To me the copy should occur regardless of the volatile value, it's linked to the change of calling convention that breaks the stack alignment assumptions.<br></div><div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 7, 2019 at 10:38 AM Guillaume Chatelet <<a href="mailto:gchatelet@google.com">gchatelet@google.com</a>> wrote:<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">On Thu, Jun 6, 2019 at 8:24 PM Eli Friedman <<a href="mailto:efriedma@quicinc.com" target="_blank">efriedma@quicinc.com</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 lang="EN-US">
<div class="gmail-m_2473166369444083368gmail-m_-1025683056797698224WordSection1">
<p class="MsoNormal">clang uses a volatile memcpy for struct assignment in C. For example, “void f(volatile struct S*p) { p[0] = p[1]; }”. It’s not really that useful, but it’s been done that way since before clang was written.<br></p></div></div></blockquote><div><br></div><div>Thx. I guess my next question is, from the code gen perspective is there a difference between the volatile and non volatile versions</div><div>> void f(volatile struct S*p) { p[0] = p[1]; }<br></div><div>and</div><div>> void f(struct S*p) { p[0] = p[1]; }</div><div><br></div><div>Clang could lower the volatile copy to a regular copy. And since memcpy has side effects it would still maintain "that volatile operations are emitted in source order relative to other volatile operations."</div><div>I tried x86_64 gcc, x86_64 clang, ARM gcc, they all generate the exact same code.</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 lang="EN-US"><div class="gmail-m_2473166369444083368gmail-m_-1025683056797698224WordSection1"><div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0in 0in 0in 4pt"><div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
</blockquote>
</div>
</div>
</div>
</div>
</blockquote></div></div>
</blockquote></div>