<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jul 22, 2019 at 4:32 PM Philip Reames via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</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">Author: reames<br>
Date: Mon Jul 22 16:33:18 2019<br>
New Revision: 366765<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=366765&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=366765&view=rev</a><br>
Log:<br>
[Statepoints] Fix a bug in statepoint lowering for functions w/no-realign-stack<br>
<br>
We were silently using the ABI alignment for all of the stores generated for deopt and gc values.  We'd gotten the alignment of the stack slot itself properly reduced (via MachineFrameInfo's clamping), but having the MMO on the store incorrect was enough for us to generate an aligned store to a unaligned location.<br>
<br>
The simplest fix would have been to just pass the alignment to the helper function, but once we do that, the helper function doesn't really help.  So, inline it and directly call the MMO version of DAG.getStore with a properly constructed MMO.<br>
<br>
Note that there's a separate performance possibility here.  Even if we *can* realign stacks, we probably don't *want to* if all of the stores are in slowpaths.  But that's a later patch, if at all.  :)<br>
<br>
<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp<br>
    llvm/trunk/test/CodeGen/X86/statepoint-no-realign-stack.ll<br>
<br>
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp?rev=366765&r1=366764&r2=366765&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp?rev=366765&r1=366764&r2=366765&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp Mon Jul 22 16:33:18 2019<br>
@@ -389,10 +389,17 @@ spillIncomingStatepointValue(SDValue Inc<br>
            "Bad spill:  stack slot does not match!");<br>
 #endif<br>
<br>
+    // Note: Using the alignment of the spill slot (rather than the abi or<br>
+    // preferred alignment) is required for correctness when dealing with spill<br>
+    // slots with preferred alignments larger than frame alignment..<br>
     auto &MF = Builder.DAG.getMachineFunction();<br>
     auto PtrInfo = MachinePointerInfo::getFixedStack(MF, Index);<br>
+    auto *StoreMMO =<br>
+      MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOStore, <br>
+                              MFI.getObjectSize(Index),<br>
+                              MFI.getObjectAlignment(Index));<br></blockquote><div> </div><div>MFI here refers to a variable above that is in a debug only section, which fails to build in non-debug builds.  In r366773 that section is no longer debug only to fix the build.</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">
     Chain = Builder.DAG.getStore(Chain, Builder.getCurSDLoc(), Incoming, Loc,<br>
-                                 PtrInfo);<br>
+                                 StoreMMO);<br>
<br>
     MMO = getMachineMemOperand(MF, *cast<FrameIndexSDNode>(Loc));<br>
<br>
<br>
Modified: llvm/trunk/test/CodeGen/X86/statepoint-no-realign-stack.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/statepoint-no-realign-stack.ll?rev=366765&r1=366764&r2=366765&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/statepoint-no-realign-stack.ll?rev=366765&r1=366764&r2=366765&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/statepoint-no-realign-stack.ll (original)<br>
+++ llvm/trunk/test/CodeGen/X86/statepoint-no-realign-stack.ll Mon Jul 22 16:33:18 2019<br>
@@ -35,14 +35,13 @@ define void @can_realign(<8 x i32>* %p)<br>
   ret void<br>
 }<br>
<br>
-; TODO: currently shows incorrect codegen, FIXME<br>
 define void @no_realign(<8 x i32>* %p) "no-realign-stack" {<br>
 ; CHECK-LABEL: no_realign:<br>
 ; CHECK:       # %bb.0:<br>
 ; CHECK-NEXT:    subq $40, %rsp<br>
 ; CHECK-NEXT:    .cfi_def_cfa_offset 48<br>
 ; CHECK-NEXT:    vmovaps (%rdi), %ymm0<br>
-; CHECK-NEXT:    vmovaps %ymm0, (%rsp)<br>
+; CHECK-NEXT:    vmovups %ymm0, (%rsp)<br>
 ; CHECK-NEXT:    vzeroupper<br>
 ; CHECK-NEXT:    callq foo<br>
 ; CHECK-NEXT:  .Ltmp1:<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>