Fix cycle in selection DAG introduced by extractelement legalization
authorRobert Lougher <rob.lougher@gmail.com>
Wed, 9 Dec 2015 14:34:10 +0000 (14:34 +0000)
committerRobert Lougher <rob.lougher@gmail.com>
Wed, 9 Dec 2015 14:34:10 +0000 (14:34 +0000)
commitf0033b29d484172f6b33019a02762b42481aeed7
treec57f87bcc1705769d5593f047cdb16824c95ade0
parent86f729296ab69755c739bc23f831871929680fbd
Fix cycle in selection DAG introduced by extractelement legalization

During selection DAG legalization, extractelement is replaced with a load
instruction.  To do this, a temporary store to the stack is used unless an
existing store is found that can be re-used.

If re-using a store, the chain going out of the store must be replaced by
the one going out of the new load (this ensures that any stores that must
take place after the store happens after the load, else the value might
be overwritten before it is loaded).

The problem is, if the extractelement index is dependent on the store
replacing the chain will introduce a cycle in the selection DAG (the load
uses the index, and by replacing the chain we will make the index dependent
on the load).

To fix this, if the index is dependent on the store, the store is skipped.
This is conservative as we may end up creating an unnecessary extra store
to the stack.  However, the situation is not expected to occur very often.

Differential Revision: http://reviews.llvm.org/D15330

llvm-svn: 255114
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
llvm/test/CodeGen/X86/extractelement-legalization-cycle.ll [new file with mode: 0644]