[WPD/LTT] Lower type test feeding assumes via phi correctly
authorTeresa Johnson <tejohnson@google.com>
Fri, 16 Sep 2022 03:23:44 +0000 (20:23 -0700)
committerTeresa Johnson <tejohnson@google.com>
Fri, 16 Sep 2022 20:50:01 +0000 (13:50 -0700)
commitc2cf93c1a9f1b8c5b886bb8847ac803d4c053dcf
treeece8fe3ca87ea16a21c53c072c2d366f34aff7c2
parent47e9e588083493414d0abfbe33fe3566879c219b
[WPD/LTT] Lower type test feeding assumes via phi correctly

This fixes https://github.com/llvm/llvm-project/issues/57616.

Type test lowering in ThinLTO modules relies on having type id
summaries set up for the referenced types, which provide the type
test resolution. If there is no summary, the type tests are lowered
to false. At the very least, a default type id summary gives the
type tests a resolution of Unknown, which is handled correctly (ignored
by the first invocation of LTT, and lowered to true by the second).

WPD sets up the type id summaries (with a default type test resolution)
as it is processing the type tests, but only does this for the patterns
handled by WPD, which is a type test directly feeding an assume. In the
case of type tests feeding an assume via a phi, the type id summary was
not being set up, leading to the type tests being lowered to false
incorrectly.

Fix this by adding the default type id summary entries for all type ids
used on globals during index-only WPD.

This is not an issue for hybrid (split-lto-unit) LTO, as in that case
the type test resolution is determined and set up during LTT, since the
type definitions are in the regular LTO split module, and exported via
the summary to the ThinLTO split module.

Differential Revision: https://reviews.llvm.org/D134012
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
llvm/test/ThinLTO/X86/lower_type_test_phi.ll [new file with mode: 0644]