Fix double renaming bug in stack coloring pass
authorRichard Sandiford <rsandifo@linux.vnet.ibm.com>
Fri, 5 Jul 2013 14:24:47 +0000 (14:24 +0000)
committerRichard Sandiford <rsandifo@linux.vnet.ibm.com>
Fri, 5 Jul 2013 14:24:47 +0000 (14:24 +0000)
commit5f1c7e5eac78349acfd6be1f9f03ccef3ba51d59
treec5f58e07c66e1373234364b8a28f819e5b42832c
parentcf1b5bd60ab7cf907bef20c3997ffb249b4fe90a
Fix double renaming bug in stack coloring pass

The stack coloring pass renumbered frame indexes with a loop of the form:

  for each frame index FI
    for each instruction I that uses FI
      for each use of FI in I
        rename FI to FI'

This caused problems if an instruction used two frame indexes F0 and F1
and if F0 was renamed to F1 and F1 to F2.  The first time we visited the
instruction we changed F0 to F1, then we changed both F1s to F2.

In other words, the problem was that SSRefs recorded which instructions
used an FI, but not which MachineOperands and MachineMemOperands within
that instruction used it.

This is easily fixed for MachineOperands by walking the instructions
once and processing each operand in turn.  There's already a loop to
do that for dead store elimination, so it seemed more efficient to
fuse the two at the block level.

MachineMemOperands are more tricky because they can be shared between
instructions.  The patch handles them by making SSRefs an array of
MachineMemOperands rather than an array of MachineInstrs.  We might end
up processing the same MachineMemOperand twice, but that's OK because
we always know from the SSRefs index what the original frame index was.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185703 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/StackSlotColoring.cpp
test/CodeGen/SystemZ/spill-01.ll