Skip to content

Commit bae08da

Browse files
authored
llvm-reduce: Preserve uselistorder when writing thinlto bitcode (#133369)
Fixes #63621
1 parent c5ac63e commit bae08da

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: opt --thinlto-bc --thinlto-split-lto-unit %s -o %t.0
2+
; RUN: llvm-reduce -write-tmp-files-as-bitcode --delta-passes=instructions %t.0 -o %t.1 \
3+
; RUN: --test %python --test-arg %p/Inputs/llvm-dis-and-filecheck.py --test-arg llvm-dis --test-arg FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s
4+
; RUN: llvm-dis --preserve-ll-uselistorder %t.1 -o %t.2
5+
; RUN: FileCheck --check-prefix=RESULT %s < %t.2
6+
7+
define i32 @func(i32 %arg0, i32 %arg1) {
8+
entry:
9+
%add0 = add i32 %arg0, 0
10+
%add1 = add i32 %add0, 0
11+
%add2 = add i32 %add1, 0
12+
%add3 = add i32 %arg1, 0
13+
%add4 = add i32 %add2, %add3
14+
ret i32 %add4
15+
}
16+
17+
; INTERESTING: uselistorder i32 0
18+
; RESULT: uselistorder i32 0, { 0, 2, 1 }
19+
uselistorder i32 0, { 3, 2, 1, 0 }

llvm/tools/llvm-reduce/ReducerWorkItem.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,8 @@ void ReducerWorkItem::readBitcode(MemoryBufferRef Data, LLVMContext &Ctx,
776776
}
777777

778778
void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const {
779+
const bool ShouldPreserveUseListOrder = true;
780+
779781
if (LTOInfo && LTOInfo->IsThinLTO && LTOInfo->EnableSplitLTOUnit) {
780782
PassBuilder PB;
781783
LoopAnalysisManager LAM;
@@ -788,7 +790,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const {
788790
PB.registerLoopAnalyses(LAM);
789791
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
790792
ModulePassManager MPM;
791-
MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr));
793+
MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr,
794+
ShouldPreserveUseListOrder));
792795
MPM.run(*M, MAM);
793796
} else {
794797
std::unique_ptr<ModuleSummaryIndex> Index;
@@ -797,8 +800,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const {
797800
Index = std::make_unique<ModuleSummaryIndex>(
798801
buildModuleSummaryIndex(*M, nullptr, &PSI));
799802
}
800-
WriteBitcodeToFile(getModule(), OutStream,
801-
/*ShouldPreserveUseListOrder=*/true, Index.get());
803+
WriteBitcodeToFile(getModule(), OutStream, ShouldPreserveUseListOrder,
804+
Index.get());
802805
}
803806
}
804807

0 commit comments

Comments
 (0)