Fix incorrect immediate size for AddrModeT2_i8s4 in rewriteT2FrameIndex.
authorBob Wilson <bob.wilson@apple.com>
Mon, 23 Feb 2015 16:57:19 +0000 (16:57 +0000)
committerBob Wilson <bob.wilson@apple.com>
Mon, 23 Feb 2015 16:57:19 +0000 (16:57 +0000)
commit89e94fc3ad67618b0e95570b9a65c082b2b86a87
tree7e68f16d81b76137d5739ae7fbf4aa6bd614b247
parent654a85e2ee08367dfbd391440fe5e69d2b3cde4f
Fix incorrect immediate size for AddrModeT2_i8s4 in rewriteT2FrameIndex.

The natural way to handle this addressing mode would be to say that it has
8 bits and gets scaled by 4, but since the MC layer is expecting the scaling
to be already reflected in the immediate value, we have been setting the
Scale to 1. That's fine, but then NumBits needs to be adjusted to reflect
the effective increase in the range of the immediate. That adjustment was
missing.

The consequence is that the register scavenger can fail.
The estimateRSStackSizeLimit() function in ARMFrameLowering.cpp correctly
assumes that the AddrModeT2_i8s4 address mode can handle scaled offsets up to
1020. Under just the right circumstances, we fail to reserve space for the
scavenger because it thinks that nothing will be needed. However, the overly
pessimistic behavior in rewriteT2FrameIndex causes some frame indexes to be
out of range and require scavenged registers, and so the scavenger asserts.

Unfortunately I have not been able to come up with a testcase for this. I
can only reproduce it on an internal branch where the frame layout and
register allocation is slightly different than trunk. We really need a
way to serialize MachineInstr-level IR to write reasonable tests for things
like this.

rdar://problem/19909005

llvm-svn: 230233
llvm/lib/Target/ARM/Thumb2InstrInfo.cpp