This is an archive of the discontinued LLVM Phabricator instance.

[LTT] Don't attempt to lower type tests used only by assumes
ClosedPublic

Authored by tejohnson on Feb 4 2021, 3:16 PM.

Details

Summary

Type tests used only by assumes were original for devirtualization, but
are meant to be kept through the first invocation of LTT so that they
can be used for additional optimization. In the regular LTO case where
the IR is analyzed we may find a resolution for the type test and end up
rewriting the associated vtable global, which can have implications on
section splitting. Simply ignore these type tests.

Fixes PR48245.

Diff Detail

Event Timeline

tejohnson created this revision.Feb 4 2021, 3:16 PM
tejohnson requested review of this revision.Feb 4 2021, 3:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2021, 3:16 PM
ilinpv accepted this revision.Feb 5 2021, 4:00 PM

LGTM, thank you for quick fix!

This revision is now accepted and ready to land.Feb 5 2021, 4:00 PM
This revision was landed with ongoing or failed builds.Feb 6 2021, 9:02 AM
This revision was automatically updated to reflect the committed changes.
pcc added inline comments.Feb 8 2021, 11:14 AM
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
2068

You can use a standard range for loop. We aren't rewriting users so you don't need this pattern here.

2069

You can dyn_cast to IntrinsicInst to reduce the amount of boilerplate here.

pcc added inline comments.Feb 8 2021, 11:19 AM
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
2067

If the intrinsic is unused then we don't want to rewrite it either so you can initialize this to true.

tejohnson added inline comments.Feb 10 2021, 1:34 PM
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
2067

I tried that but it broke a half dozen or so LTT tests (e.g. llvm/test/Transforms/LowerTypeTests/layout.ll) where there were type tests and no uses of the results. The other possibility was to change those tests, but I thought with this initial value it would simplify creating tests. WDYT?

2068

Will fix

2069

Will fix (here and in another place in this file that has the same pattern)

Fixed most of the suggestions at a80232bd5f125ab81554882825a564bdc7ab8e0c. Question about the other one below.

llvm/lib/Transforms/IPO/LowerTypeTests.cpp
2067

I could change this if I made fixes like this one to ~6 of the LTT tests to make sure the type test results are used before invoking the LTT pass on its own via opt. Let me know what you prefer to do here. Not sure if this makes it more of a pain to test?

diff --git a/llvm/test/Transforms/LowerTypeTests/layout.ll b/llvm/test/Transforms/LowerTypeTests/layout.ll
index 7075955790d9..38fe5be10aad 100644
--- a/llvm/test/Transforms/LowerTypeTests/layout.ll
+++ b/llvm/test/Transforms/LowerTypeTests/layout.ll
@@ -18,10 +18,12 @@ target datalayout = "e-p:32:32"
 !2 = !{i32 0, !"typeid3"}
 
 declare i1 @llvm.type.test(i8* %ptr, metadata %bitset) nounwind readnone
+declare void @bar(i1 %x, i1 %y, i1 %z)
 
 define void @foo() {
   %x = call i1 @llvm.type.test(i8* undef, metadata !"typeid1")
   %y = call i1 @llvm.type.test(i8* undef, metadata !"typeid2")
   %z = call i1 @llvm.type.test(i8* undef, metadata !"typeid3")
+  call void @bar(i1 %x, i1 %y, i1 %z)
   ret void
 }