Skip to content

Commit 68a064b

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.4 [skip ci]
1 parent 7cbb365 commit 68a064b

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

llvm/include/llvm/Transforms/IPO/LowerTypeTests.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,15 @@ class LowerTypeTestsPass : public PassInfoMixin<LowerTypeTestsPass> {
203203
ModuleSummaryIndex *ExportSummary = nullptr;
204204
const ModuleSummaryIndex *ImportSummary = nullptr;
205205
bool DropTypeTests = true;
206+
bool AlwaysDropTests = false;
206207

207208
public:
208209
LowerTypeTestsPass() : UseCommandLine(true) {}
209210
LowerTypeTestsPass(ModuleSummaryIndex *ExportSummary,
210211
const ModuleSummaryIndex *ImportSummary,
211-
bool DropTypeTests = false)
212+
bool DropTypeTests = false, bool AlwaysDropTests = false)
212213
: ExportSummary(ExportSummary), ImportSummary(ImportSummary),
213-
DropTypeTests(DropTypeTests) {}
214+
DropTypeTests(DropTypeTests), AlwaysDropTests(AlwaysDropTests) {}
214215
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
215216
};
216217

llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ static cl::opt<bool>
122122
ClDropTypeTests("lowertypetests-drop-type-tests",
123123
cl::desc("Simply drop type test assume sequences"),
124124
cl::Hidden, cl::init(false));
125+
static cl::opt<bool>
126+
ClForceDropTypeTests("lowertypetests-force-drop-type-tests",
127+
cl::desc("Always drop all type test sequences"),
128+
cl::Hidden, cl::init(false));
125129

126130
bool BitSetInfo::containsGlobalOffset(uint64_t Offset) const {
127131
if (Offset < ByteOffset)
@@ -400,6 +404,7 @@ class LowerTypeTestsModule {
400404
// Set when the client has invoked this to simply drop all type test assume
401405
// sequences.
402406
bool DropTypeTests;
407+
bool AlwaysDropTests;
403408

404409
Triple::ArchType Arch;
405410
Triple::OSType OS;
@@ -542,7 +547,7 @@ class LowerTypeTestsModule {
542547
LowerTypeTestsModule(Module &M, ModuleAnalysisManager &AM,
543548
ModuleSummaryIndex *ExportSummary,
544549
const ModuleSummaryIndex *ImportSummary,
545-
bool DropTypeTests);
550+
bool DropTypeTests, bool AlwaysDropTests);
546551

547552
bool lower();
548553

@@ -1828,9 +1833,11 @@ void LowerTypeTestsModule::buildBitSetsFromDisjointSet(
18281833
/// Lower all type tests in this module.
18291834
LowerTypeTestsModule::LowerTypeTestsModule(
18301835
Module &M, ModuleAnalysisManager &AM, ModuleSummaryIndex *ExportSummary,
1831-
const ModuleSummaryIndex *ImportSummary, bool DropTypeTests)
1836+
const ModuleSummaryIndex *ImportSummary, bool DropTypeTests,
1837+
bool AlwaysDropTests)
18321838
: M(M), ExportSummary(ExportSummary), ImportSummary(ImportSummary),
1833-
DropTypeTests(DropTypeTests || ClDropTypeTests) {
1839+
DropTypeTests(DropTypeTests || ClDropTypeTests),
1840+
AlwaysDropTests(AlwaysDropTests || ClForceDropTypeTests) {
18341841
assert(!(ExportSummary && ImportSummary));
18351842
Triple TargetTriple(M.getTargetTriple());
18361843
Arch = TargetTriple.getArch();
@@ -1882,7 +1889,7 @@ bool LowerTypeTestsModule::runForTesting(Module &M, ModuleAnalysisManager &AM) {
18821889
M, AM,
18831890
ClSummaryAction == PassSummaryAction::Export ? &Summary : nullptr,
18841891
ClSummaryAction == PassSummaryAction::Import ? &Summary : nullptr,
1885-
/*DropTypeTests*/ false)
1892+
/*DropTypeTests*/ false, /*AlwaysDropTests=*/false)
18861893
.lower();
18871894

18881895
if (!ClWriteSummary.empty()) {
@@ -1949,7 +1956,7 @@ void LowerTypeTestsModule::replaceDirectCalls(Value *Old, Value *New) {
19491956
Old->replaceUsesWithIf(New, isDirectCall);
19501957
}
19511958

1952-
static void dropTypeTests(Module &M, Function &TypeTestFunc) {
1959+
static void dropTypeTests(Module &M, Function &TypeTestFunc, bool AlwaysDrop) {
19531960
for (Use &U : llvm::make_early_inc_range(TypeTestFunc.uses())) {
19541961
auto *CI = cast<CallInst>(U.getUser());
19551962
// Find and erase llvm.assume intrinsics for this llvm.type.test call.
@@ -1960,8 +1967,9 @@ static void dropTypeTests(Module &M, Function &TypeTestFunc) {
19601967
// phi (which will feed the assume). Simply replace the use on the phi
19611968
// with "true" and leave the merged assume.
19621969
if (!CI->use_empty()) {
1963-
assert(
1964-
all_of(CI->users(), [](User *U) -> bool { return isa<PHINode>(U); }));
1970+
assert(AlwaysDrop || all_of(CI->users(), [](User *U) -> bool {
1971+
return isa<PHINode>(U);
1972+
}));
19651973
CI->replaceAllUsesWith(ConstantInt::getTrue(M.getContext()));
19661974
}
19671975
CI->eraseFromParent();
@@ -1974,14 +1982,14 @@ bool LowerTypeTestsModule::lower() {
19741982

19751983
if (DropTypeTests) {
19761984
if (TypeTestFunc)
1977-
dropTypeTests(M, *TypeTestFunc);
1985+
dropTypeTests(M, *TypeTestFunc, AlwaysDropTests);
19781986
// Normally we'd have already removed all @llvm.public.type.test calls,
19791987
// except for in the case where we originally were performing ThinLTO but
19801988
// decided not to in the backend.
19811989
Function *PublicTypeTestFunc =
19821990
M.getFunction(Intrinsic::getName(Intrinsic::public_type_test));
19831991
if (PublicTypeTestFunc)
1984-
dropTypeTests(M, *PublicTypeTestFunc);
1992+
dropTypeTests(M, *PublicTypeTestFunc, AlwaysDropTests);
19851993
if (TypeTestFunc || PublicTypeTestFunc) {
19861994
// We have deleted the type intrinsics, so we no longer have enough
19871995
// information to reason about the liveness of virtual function pointers
@@ -2449,9 +2457,9 @@ PreservedAnalyses LowerTypeTestsPass::run(Module &M,
24492457
if (UseCommandLine)
24502458
Changed = LowerTypeTestsModule::runForTesting(M, AM);
24512459
else
2452-
Changed =
2453-
LowerTypeTestsModule(M, AM, ExportSummary, ImportSummary, DropTypeTests)
2454-
.lower();
2460+
Changed = LowerTypeTestsModule(M, AM, ExportSummary, ImportSummary,
2461+
DropTypeTests, AlwaysDropTests)
2462+
.lower();
24552463
if (!Changed)
24562464
return PreservedAnalyses::all();
24572465
return PreservedAnalyses::none();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: opt -S -passes=lowertypetests -lowertypetests-force-drop-type-tests -lowertypetests-drop-type-tests < %s | FileCheck %s
2+
3+
define void @func() {
4+
entry:
5+
%0 = tail call i1 @llvm.type.test(ptr null, metadata !"foo")
6+
br i1 %0, label %exit, label %trap
7+
; CHECK: entry:
8+
; CHECK-NEXT: br i1 true, label %exit, label %trap
9+
; CHECK-NOT: @llvm.type.test
10+
11+
trap:
12+
unreachable
13+
14+
exit:
15+
ret void
16+
}
17+
18+
declare i1 @llvm.type.test(ptr, metadata) #0
19+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

0 commit comments

Comments
 (0)