ARM: Fix a bug which was causing convergence failure in constant-island pass.
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 17 Oct 2014 01:31:47 +0000 (01:31 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 17 Oct 2014 01:31:47 +0000 (01:31 +0000)
commit0d0c78180d3ca9ec8ae06d64b96b4b0cf4f022a7
treef4d0d441b6a4740ad337ee5bd5ca2b0448513841
parentd963ca6739ad59d70a2cbae43a7f23eed335f746
ARM: Fix a bug which was causing convergence failure in constant-island pass.

The bug is in ARMConstantIslands::createNewWater where the upper bound of the
new water split point is computed:

// This could point off the end of the block if we've already got constant
// pool entries following this block; only the last one is in the water list.
// Back past any possible branches (allow for a conditional and a maximally
// long unconditional).
if (BaseInsertOffset + 8 >= UserBBI.postOffset()) {
  BaseInsertOffset = UserBBI.postOffset() - UPad - 8;
  DEBUG(dbgs() << format("Move inside block: %#x\n", BaseInsertOffset));
}

The split point is supposed to be somewhere between the machine instruction that
loads from the constant pool entry and the end of the basic block, before branch
instructions. The code above is fine if the basic block is large enough and
there are a sufficient number of instructions following the machine instruction.
However, if the machine instruction is near the end of the basic block,
BaseInsertOffset can point to the machine instruction or another instruction
that precedes it, and this can lead to convergence failure.

This commit fixes this bug by ensuring BaseInsertOffset is larger than the
offset of the instruction following the constant-loading instruction.

rdar://problem/18581150

llvm-svn: 220015
llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
llvm/test/CodeGen/Thumb2/constant-islands-new-island.ll [new file with mode: 0644]