Skip to content

Commit 64c6fea

Browse files
committed
llvm-reduce: Preserve uselistorder when writing thinlto bitcode
Fixes #63621
1 parent d0e10cb commit 64c6fea

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,11 @@ 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) {
782+
// FIXME: This should not depend on the pass manager. There are hidden
783+
// transforms that may happen inside ThinLTOBitcodeWriterPass
780784
PassBuilder PB;
781785
LoopAnalysisManager LAM;
782786
FunctionAnalysisManager FAM;
@@ -788,7 +792,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const {
788792
PB.registerLoopAnalyses(LAM);
789793
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
790794
ModulePassManager MPM;
791-
MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr));
795+
MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr,
796+
ShouldPreserveUseListOrder));
792797
MPM.run(*M, MAM);
793798
} else {
794799
std::unique_ptr<ModuleSummaryIndex> Index;
@@ -797,8 +802,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const {
797802
Index = std::make_unique<ModuleSummaryIndex>(
798803
buildModuleSummaryIndex(*M, nullptr, &PSI));
799804
}
800-
WriteBitcodeToFile(getModule(), OutStream,
801-
/*ShouldPreserveUseListOrder=*/true, Index.get());
805+
WriteBitcodeToFile(getModule(), OutStream, ShouldPreserveUseListOrder,
806+
Index.get());
802807
}
803808
}
804809

0 commit comments

Comments
 (0)