[llvm-branch-commits] [llvm-branch] r351530 - Merging r351475:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 18 00:59:51 PST 2019


Author: hans
Date: Fri Jan 18 00:59:50 2019
New Revision: 351530

URL: http://llvm.org/viewvc/llvm-project?rev=351530&view=rev
Log:
Merging r351475:
------------------------------------------------------------------------
r351475 | rnk | 2019-01-17 21:46:53 +0100 (Thu, 17 Jan 2019) | 16 lines

[InstCombine] Don't sink dynamic allocas

Summary:
InstCombine's sinking algorithm only thinks about memory. It doesn't
think about non-memory constraints like stack object lifetime. It can
sink dynamic allocas across a stacksave call, which may be used with
stackrestore, which can incorrectly reduce the lifetime of the dynamic
alloca.

Fixes PR40365

Reviewers: hfinkel, efriedma

Subscribers: hiraditya, llvm-commits

Differential Revision: https://reviews.llvm.org/D56872
------------------------------------------------------------------------

Added:
    llvm/branches/release_80/test/Transforms/InstCombine/sink-alloca.ll
      - copied unchanged from r351475, llvm/trunk/test/Transforms/InstCombine/sink-alloca.ll
Modified:
    llvm/branches/release_80/   (props changed)
    llvm/branches/release_80/lib/Transforms/InstCombine/InstructionCombining.cpp

Propchange: llvm/branches/release_80/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jan 18 00:59:50 2019
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,351344-351345,351349,351351,351370,351381,351421,351436
+/llvm/trunk:155241,351344-351345,351349,351351,351370,351381,351421,351436,351475

Modified: llvm/branches/release_80/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_80/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=351530&r1=351529&r2=351530&view=diff
==============================================================================
--- llvm/branches/release_80/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/branches/release_80/lib/Transforms/InstCombine/InstructionCombining.cpp Fri Jan 18 00:59:50 2019
@@ -3065,9 +3065,11 @@ static bool TryToSinkInstruction(Instruc
       I->isTerminator())
     return false;
 
-  // Do not sink alloca instructions out of the entry block.
-  if (isa<AllocaInst>(I) && I->getParent() ==
-        &DestBlock->getParent()->getEntryBlock())
+  // Do not sink static or dynamic alloca instructions. Static allocas must
+  // remain in the entry block, and dynamic allocas must not be sunk in between
+  // a stacksave / stackrestore pair, which would incorrectly shorten its
+  // lifetime.
+  if (isa<AllocaInst>(I))
     return false;
 
   // Do not sink into catchswitch blocks.




More information about the llvm-branch-commits mailing list