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)
commitc8a1727001447d1dc04df35f5b4e282651186345
tree724acac3954b4e4edfef5ea9661b7d752f1c927b
parent43ecf2d4d1d9c89b0a7519708bfce9c728d51f08
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255114 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
test/CodeGen/X86/extractelement-legalization-cycle.ll [new file with mode: 0644]