Fix mem2reg to correctly handle allocas only used in a single block
authorMichael Kuperstein <michael.m.kuperstein@intel.com>
Wed, 22 Jul 2015 10:29:29 +0000 (10:29 +0000)
committerMichael Kuperstein <michael.m.kuperstein@intel.com>
Wed, 22 Jul 2015 10:29:29 +0000 (10:29 +0000)
commit6418278e7de1f4431abea459de4ee37d5cc4b548
tree57e2b92bb9ca1e023f0ac7011c6a3cf0db368e77
parenta5812d5bbf0a13190b48ac9819ab940e68762239
Fix mem2reg to correctly handle allocas only used in a single block

Currently, a load from an alloca that is used in as single block and is not preceded
by a store is replaced by undef. This is not always correct if the single block is
inside a loop.
Fix the logic so that:
1) If there are no stores in the block, replace the load with an undef, as before.
2) If there is a store (regardless of where it is in the block w.r.t the load), bail
out, and let the rest of mem2reg handle this alloca.

Patch by: gil.rapaport@intel.com
Differential Revision: http://reviews.llvm.org/D11355

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242884 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/PromoteMemoryToRegister.cpp
test/Transforms/Mem2Reg/pr24179.ll [new file with mode: 0644]