[Verifier] Reject PHIs using defs from own block.
authorMichael Kruse <llvm@meinersbur.de>
Sat, 26 Mar 2016 23:32:57 +0000 (23:32 +0000)
committerMichael Kruse <llvm@meinersbur.de>
Sat, 26 Mar 2016 23:32:57 +0000 (23:32 +0000)
commitff379b69b2f82c9ca9b955b0458bb1aba85b9b85
treea97fa4b07963885e08e501d48ef4260d4ff549ba
parent796db35f622d0730347a09a9b675bc5e113db9c3
[Verifier] Reject PHIs using defs from own block.

Reject the following IR as malformed (assuming that %entry, %next are
not in a loop):

    next:
      %y = phi i32 [ 0, %entry ]
      %x = phi i32 [ %y, %entry ]

Such PHI nodes came up in PR26718. While there was no consensus on
whether or not this is valid IR, most opinions on that bug and in a
discussion on the llvm-dev mailing list tended towards a
"strict interpretation" (term by Joseph Tremoulet) of PHI node uses.
Also, the language reference explicitly states that "the use of each
incoming value is deemed to occur on the edge from the corresponding
predecessor block to the current block" and
`DominatorTree::dominates(Instruction*, Use&)` uses this definition as
well.

For the code mentioned in PR15384, clang does not compile to such PHIs
(anymore?). The test case still hangs when replacing `%tmp6` with `%tmp`
in revisions before r176366 (where PR15384 has been fixed). The
occurrence of %tmp6 therefore was probably unintentional. Its value is
not used except in other PHIs.

Reviewers: majnemer, reames, JosephTremoulet, bkramer, grosser, jdoerfert, kparzysz, sanjoy

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

llvm-svn: 264528
llvm/lib/IR/Verifier.cpp
llvm/test/Transforms/LoopVectorize/phi-hang.ll
llvm/test/Verifier/dominates.ll