[Mem2Reg] Fix nondeterministic corner case
authorJoseph Tremoulet <jotrem@microsoft.com>
Fri, 30 Nov 2018 19:20:02 +0000 (19:20 +0000)
committerJoseph Tremoulet <jotrem@microsoft.com>
Fri, 30 Nov 2018 19:20:02 +0000 (19:20 +0000)
commit27b1e3bd4f7a064a2672e30cc6be31433ebd300b
tree15f23643971ffcb02f36f19a68c1d29d91693c08
parente024c8b2127fbe79bcf3aa10923bdc69af2bea51
[Mem2Reg] Fix nondeterministic corner case

Summary:
When mem2reg inserts phi nodes in blocks with unreachable predecessors,
it adds undef operands for those incoming edges.  When there are
multiple such predecessors, the order is currently based on the address
of the BasicBlocks.  This change fixes that by using the BBNumbers in
the sort/search predicates, as is done elsewhere in mem2reg to ensure
determinism.

Also adds a testcase with a bunch of unreachable preds, which
(nodeterministically) fails without the fix.

Reviewers: majnemer

Reviewed By: majnemer

Subscribers: mgrang, llvm-commits

Differential Revision: https://reviews.llvm.org/D55077

llvm-svn: 348024
llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
llvm/test/Transforms/Mem2Reg/undef-order.ll [new file with mode: 0644]