Fix a somewhat nasty crasher in PR13378. This crashes inside of
authorChandler Carruth <chandlerc@gmail.com>
Wed, 18 Jul 2012 18:58:22 +0000 (18:58 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 18 Jul 2012 18:58:22 +0000 (18:58 +0000)
commit32d75bec4bbbd97b70d887ed3c106951b1d18182
tree6bdda974c125c72165c8e95e4106df1efbcf37eb
parent8d8d961de4878b17dca9d8b23666df223f6d654b
Fix a somewhat nasty crasher in PR13378. This crashes inside of
LiveIntervals due to the two-addr pass generating bogus MI code.

The crux of the issue was a loop nesting problem. The intent of the code
which attempts to transform instructions before converting them to
two-addr form is to defer and reprocess any transformed instructions as
the second processing is likely to have more opportunities to coalesce
copies, etc. Unfortunately, there was one section of processing that was
not deferred -- the INSERT_SUBREG rewriting. Due to quirks of how this
rewriting proceeded, not only did it occur early, it removed the bits of
information needed for the deferred processing to correctly generate the
necessary two address form (specifically inserting a copy), but didn't
trigger any immediate assertions and produced what appeared to be
already valid two-address from code. Thus, the assertion only fired much
later in the pipeline.

The fix is to hoist the transformation logic up layer to where it can
more firmly defer all further processing, and to teach the normal
processing to handle an edge case previously handled as part of the
transformation logic. This edge case (already matched tied register
operands) needs to *not* defer any steps.

As has been brought up repeatedly in the process: wow does this code
need refactoring. I *may* squeeze in some time to at least bring sanity
to this loop... but wow... =]

Thanks to Jakob for helpful hints on the way here, and the review.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160443 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/TwoAddressInstructionPass.cpp
test/CodeGen/ARM/twoaddrinstr.ll [new file with mode: 0644]