[Inline] Fix noalias addition on simplified instructions (PR50589)
authorNikita Popov <nikita.ppv@gmail.com>
Sun, 18 Jul 2021 16:33:32 +0000 (18:33 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 20 Jul 2021 17:52:41 +0000 (19:52 +0200)
commitea014c5bbfa7bff4ebf4631204ca2d6d129a94d7
tree791363dcceb63fc68d2090ade93235a780a96067
parente8bc871ca2780788ad580bb23ef2621b09e6394b
[Inline] Fix noalias addition on simplified instructions (PR50589)

When adding noalias/alias.scope metadata, we analyze the instructions
of the original callee, and then place metadata on the corresponding
inlined instructions in the caller as provided by VMap. However, this
assumes that this actually a clone of the instruction, rather than
the result of simplification. If simplification occurred, the
instruction that VMap points to may not have any relationship as far
as ModRef behavior is concerned.

Fix this by tracking simplified instructions during cloning and then
only processing instructions that have not been simplified. This is
done with an additional map form original to cloned instruction,
into which we only insert if no simplification is performed. The
mapping in VMap can then be compared to this map. If they're the
same, the instruction hasn't been simplified. (I originally wanted
to only track a set of simplified instructions, but that wouldn't
work if the instruction only gets simplified afterwards, e.g. based
on rewritten phis.)

Fixes https://bugs.llvm.org/show_bug.cgi?id=50589.

Differential Revision: https://reviews.llvm.org/D106242
llvm/include/llvm/Transforms/Utils/Cloning.h
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Transforms/Inline/pr50589.ll