[NewGVN] Fix a consistent order for phi nodes operands.
authorDavide Italiano <davide@freebsd.org>
Tue, 9 May 2017 16:58:28 +0000 (16:58 +0000)
committerDavide Italiano <davide@freebsd.org>
Tue, 9 May 2017 16:58:28 +0000 (16:58 +0000)
commitd6bb8cab0315018dd13b42fb25709dee0ca30471
tree8852562b9b20010b6dfe02fb65dfb5a650f21eac
parent0acb6654d365508a2732d83134dff22daae1abee
[NewGVN] Fix a consistent order for phi nodes operands.

The way we currently define congruency for two PHIExpression(s) is:

1) The operands to the phi functions are congruent
2) The PHIs are defined in the same BasicBlock.

NewGVN works under the assumption that phi operands are in predecessor
order, or at least in some consistent order. OTOH, is valid IR:

patatino:
  %meh = phi i16 [ %0, %winky ], [ %conv1, %tinky ]
  %banana = phi i16 [ %0, %tinky ], [ %conv1, %winky ]
  br label %end

and the in-memory representations of the two SSA registers have an
inconsistent order. This violation of NewGVN assumptions results into
two PHIs found congruent when they're not. While we think it's useful
to have always a consistent order enforced, let's fix this in NewGVN
sorting uses in predecessor order before creating a PHI expression.

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

llvm-svn: 302552
llvm/lib/Transforms/Scalar/NewGVN.cpp
llvm/test/Transforms/NewGVN/pr32952.ll [new file with mode: 0644]