Skip to content

Commit ed69586

Browse files
committed
llvm-reduce: Preserve uselistorder when writing thinlto bitcode
Fixes #63621
1 parent 2df298a commit ed69586

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
@@ -769,7 +769,11 @@ void ReducerWorkItem::readBitcode(MemoryBufferRef Data, LLVMContext &Ctx,
769769
}
770770

771771
void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const {
772+
const bool ShouldPreserveUseListOrder = true;
773+
772774
if (LTOInfo && LTOInfo->IsThinLTO && LTOInfo->EnableSplitLTOUnit) {
775+
// FIXME: This should not depend on the pass manager. There are hidden
776+
// transforms that may happen inside ThinLTOBitcodeWriterPass
773777
PassBuilder PB;
774778
LoopAnalysisManager LAM;
775779
FunctionAnalysisManager FAM;
@@ -781,7 +785,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const {
781785
PB.registerLoopAnalyses(LAM);
782786
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
783787
ModulePassManager MPM;
784-
MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr));
788+
MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr,
789+
ShouldPreserveUseListOrder));
785790
MPM.run(*M, MAM);
786791
} else {
787792
std::unique_ptr<ModuleSummaryIndex> Index;
@@ -790,8 +795,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const {
790795
Index = std::make_unique<ModuleSummaryIndex>(
791796
buildModuleSummaryIndex(*M, nullptr, &PSI));
792797
}
793-
WriteBitcodeToFile(getModule(), OutStream,
794-
/*ShouldPreserveUseListOrder=*/true, Index.get());
798+
WriteBitcodeToFile(getModule(), OutStream, ShouldPreserveUseListOrder,
799+
Index.get());
795800
}
796801
}
797802

0 commit comments

Comments
 (0)