This is an archive of the discontinued LLVM Phabricator instance.

llvm-reduce: Support emitting bitcode for final result
ClosedPublic

Authored by arsenm on Oct 26 2022, 2:20 PM.

Details

Summary

Previously, this unconditionally emitted text IR. I ran
into a bug that manifested in broken disassembly, so the
desired output was the bitcode format. If the input format
was binary bitcode, the requested output file ends in .bc,
or an explicit -output-bitcode option was used, emit bitcode.

Diff Detail

Event Timeline

arsenm created this revision.Oct 26 2022, 2:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 26 2022, 2:20 PM
arsenm requested review of this revision.Oct 26 2022, 2:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 26 2022, 2:20 PM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm updated this revision to Diff 470960.Oct 26 2022, 3:27 PM

My specialty continues to be failing on the most common case

wdyt about replacing -output-bitcode with -output-type=autodetect|bitcode|text, defaulting to autodetect? that seems conceptually cleaner than this logic, which has a weird imbalance between preferring bitcode vs text

wdyt about replacing -output-bitcode with -output-type=autodetect|bitcode|text, defaulting to autodetect? that seems conceptually cleaner than this logic, which has a weird imbalance between preferring bitcode vs text

I thought about doing this. We have so little consistency throughout the tools for this. Most seem to use -S to switch to text, and I don't think any try to detect based on the file extension. Since it's a reduction tool, the most sensible thing would probably be to just consistently reuse the input type (this also applies to -write-tmp-files-as-bitcode. Most of the tools happen to accept .ll or .bc inputs, but you could be reducing something that specifically needs one or the other)

arsenm updated this revision to Diff 471699.Oct 28 2022, 6:42 PM

Drop file extension based guess. Just preserve the input format, or follow the existing flag

aeubanks accepted this revision.Oct 31 2022, 1:57 PM
aeubanks added inline comments.
llvm/test/tools/llvm-reduce/Inputs/test-output-format.ll
2

can you use llvm-as instead of checking in the .bc file?

llvm/tools/llvm-reduce/ReducerWorkItem.h
47

returning std::pair<std::unique_ptr<ReducerWorkItem>, bool> and using C++17 structured bindings seems nicer

llvm/tools/llvm-reduce/llvm-reduce.cpp
161

does auto [OutputFileName, OutputBitcode] = work?

This revision is now accepted and ready to land.Oct 31 2022, 1:57 PM