OSDN Git Service

[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)
commit9689ee1fa3254923724cff3917368fabb0359215
tree1262131f66196bcb45ecc5ee584f9bdc42b2629d
parent80f6556e8a9228af17e658ca06523d1634b24c18
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302552 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/NewGVN.cpp
test/Transforms/NewGVN/pr32952.ll [new file with mode: 0644]