[InlineSpiller] Fix rematerialization for bundles.
authorQuentin Colombet <qcolombet@apple.com>
Thu, 21 May 2015 21:41:55 +0000 (21:41 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Thu, 21 May 2015 21:41:55 +0000 (21:41 +0000)
commit3ad083f2cb14874b47202ff2ad62ef3d3678fa0c
treebb2c337dfce8ee1aa105e795a809ab099881f29d
parent676efa4d56f27819d043c4090553e0b463f5e9c0
[InlineSpiller] Fix rematerialization for bundles.

Prior to this patch, we could update the operand of another MI in the same
bundle.

Longer version:
Before InlineSpiller rematerializes a vreg, it iterates over operands of each MI
in a bundle, collecting all (MI, OpNo) pairs that reference that vreg.

Then if it does rematerialize, it goes through the pair list and replaces the
operands with the new (rematerialized) vreg.  The problem is, it tries to
replace all of these operands in the main MI ! This works fine for single MIs.
However, if we are processing a bundle of MIs and the list contains multiple
pairs - the rematerialization will either crash trying to access a non-existing
operand of the main MI, or silently corrupt one of the existing ones. It will
also ignore other MIs in the bundle.

The obvious fix is to use the MI pointers saved in collected (MI, OpNo) pairs.
This must have been the original intent of the pair list but somehow these
pointers got lost.

Patch by Dmitri Shtilman <dshtilman@icloud.com>!

Differential revision: http://reviews.llvm.org/D9904

<rdar://problem/21002163>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237964 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/InlineSpiller.cpp