[llvm-branch-commits] [llvm-branch] r309577 - Merging r309343:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jul 31 09:45:02 PDT 2017

Author: hans
Date: Mon Jul 31 09:45:02 2017
New Revision: 309577

URL: http://llvm.org/viewvc/llvm-project?rev=309577&view=rev
Merging r309343:
r309343 | rnk | 2017-07-27 17:58:35 -0700 (Thu, 27 Jul 2017) | 16 lines

[X86] Fix latent bug in sibcall eligibility logic

The X86 tail call eligibility logic was correct when it was written, but
the addition of inalloca and argument copy elision broke its
assumptions. It was assuming that fixed stack objects were immutable.

Currently, we aim to emit a tail call if no arguments have to be
re-arranged in memory. This code would trace the outgoing argument
values back to check if they are loads from an incoming stack object.
If the stack argument is immutable, then we won't need to store it back
to the stack when we tail call.

Fortunately, stack objects track their mutability, so we can just make
the obvious check to fix the bug.

This was http://crbug.com/749826

      - copied unchanged from r309343, llvm/trunk/test/CodeGen/X86/tail-call-mutable-memarg.ll
    llvm/branches/release_50/   (props changed)

Propchange: llvm/branches/release_50/
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jul 31 09:45:02 2017
@@ -1,3 +1,3 @@

Modified: llvm/branches/release_50/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_50/lib/Target/X86/X86ISelLowering.cpp?rev=309577&r1=309576&r2=309577&view=diff
--- llvm/branches/release_50/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/branches/release_50/lib/Target/X86/X86ISelLowering.cpp Mon Jul 31 09:45:02 2017
@@ -3984,6 +3984,13 @@ bool MatchingStackOffset(SDValue Arg, un
   if (Offset != MFI.getObjectOffset(FI))
     return false;
+  // If this is not byval, check that the argument stack object is immutable.
+  // inalloca and argument copy elision can create mutable argument stack
+  // objects. Byval objects can be mutated, but a byval call intends to pass the
+  // mutated memory.
+  if (!Flags.isByVal() && !MFI.isImmutableObjectIndex(FI))
+    return false;
   if (VA.getLocVT().getSizeInBits() > Arg.getValueSizeInBits()) {
     // If the argument location is wider than the argument type, check that any
     // extension flags match.

More information about the llvm-branch-commits mailing list