OSDN Git Service

[CGP] Prevent optimizePhiType from iterating forever
authorDavid Green <david.green@arm.com>
Sun, 13 Sep 2020 15:11:01 +0000 (16:11 +0100)
committerDavid Green <david.green@arm.com>
Sun, 13 Sep 2020 15:11:01 +0000 (16:11 +0100)
commit9237fde48139400764377eb73e7e5d3bc5b7fffc
tree507a60a0339118b58bd1b650a28a01fcd30283d8
parent2c85f5e642fb599f77aac0de22316c922cfd7cbb
[CGP] Prevent optimizePhiType from iterating forever

The recently added optimizePhiType algorithm had no checks to make sure
it didn't continually iterate backward and forth between float and int
types. This means that given an input like store(phi(bitcast(load))), we
could convert that back and forth to store(bitcast(phi(load))). This
particular case would usually have been simplified to a different load
type (folding the bitcast into the load) before CGP, but other cases can
occur. The one that came up was phi(bitcast(phi)), where the two phi's
of different types were bitcast between. That was not helped by a dead
bitcast being kept around which could make conversion look profitable.

This adds an extra check of the bitcast Uses or Defs, to make sure that
at least one is grounded and will not end up being converted back. It
also makes sure that dead bitcasts are removed, and there is a minor
change to include newly created Phi nodes in the Visited set so that
they do not need to be revisited.

Differential Revision: https://reviews.llvm.org/D82676
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/test/CodeGen/AArch64/convertphitype.ll