This is an archive of the discontinued LLVM Phabricator instance.

[GlobalIsel][X86] Legalize G_BSWAP
ClosedPublic

Authored by tschuett on May 16 2023, 6:47 AM.

Details

Summary

remark: unable to legalize instruction: %95:_(s16) = G_BSWAP %94:_ (in function: _ZNK4llvm13DataExtractor6getU16EPyPtj) [-Rpass-missed=gisel-legalize]

check plan: ninja check-llvm-codegen-x86

Diff Detail

Event Timeline

tschuett created this revision.May 16 2023, 6:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 6:47 AM
tschuett requested review of this revision.May 16 2023, 6:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 6:47 AM
arsenm accepted this revision.May 16 2023, 6:58 AM
arsenm added inline comments.
llvm/test/CodeGen/X86/GlobalISel/legalize-bswap.mir
3

Don't need -O0

9–18

Don't need any of this in any legalize tests

This revision is now accepted and ready to land.May 16 2023, 6:58 AM
tschuett updated this revision to Diff 522597.May 16 2023, 7:01 AM

removed -O0

Thanks!

llvm/test/CodeGen/X86/GlobalISel/legalize-bswap.mir
9–18

It comes from the checks script.

This revision was landed with ongoing or failed builds.May 16 2023, 7:03 AM
This revision was automatically updated to reflect the committed changes.
arsenm added inline comments.May 16 2023, 7:09 AM
llvm/test/CodeGen/X86/GlobalISel/legalize-bswap.mir
9–18

The checks script don't modify the tests themselves. We have really bad MIRPrinter defaults and you don't need any of this header

bjope added a subscriber: bjope.May 16 2023, 7:42 AM

This seems to have broken lots of tests.
I reverted your patch here: https://github.com/llvm/llvm-project/commit/e016fe817c8e4774c3996314b9519f8d856cc616

See for example this build bot:

https://lab.llvm.org/buildbot/#/builders/16/builds/48152
bjope added a comment.May 16 2023, 7:44 AM

This seems to have broken lots of tests.
I reverted your patch here: https://github.com/llvm/llvm-project/commit/e016fe817c8e4774c3996314b9519f8d856cc616

See for example this build bot:

https://lab.llvm.org/buildbot/#/builders/16/builds/48152

Solution is probably to use

getActionDefinitionsBuilder(G_BSWAP)

instead of having the initializer list with one element.

Apple Clang didn't mind. But indeed that was the problem.

JDevlieghere added a subscriber: JDevlieghere.EditedMay 16 2023, 8:31 AM

It looks like this is hitting an assert when building compiler-rt: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/55179/console

Assertion failed: (Opcodes.size() >= 2 && "Initializer list must have at least two opcodes"), function getActionDefinitionsBuilder, file /Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp, line 300.

 #0 0x0000000106d9e037 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x101d74037)
 #1 0x0000000106d9bf24 llvm::sys::RunSignalHandlers() (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x101d71f24)
 #2 0x0000000106d9e8f0 SignalHandler(int) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x101d748f0)
 #3 0x00007fff203c8d7d (/usr/lib/system/libsystem_platform.dylib+0x7fff20353d7d)
 #4 0x00007fef100b01e8 
 #5 0x00007fff202d8406 (/usr/lib/system/libsystem_c.dylib+0x7fff20263406)
 #6 0x00007fff202d77d8 (/usr/lib/system/libsystem_c.dylib+0x7fff202627d8)
 #7 0x000000010acebb93 llvm::LegalizerInfo::getActionDefinitionsBuilder(std::initializer_list<unsigned int>) (.cold.1) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x105cc1b93)
 #8 0x0000000107d29b35 llvm::LegalizerInfo::getActionDefinitionsBuilder(std::initializer_list<unsigned int>) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x102cffb35)
 #9 0x0000000105337b52 llvm::X86LegalizerInfo::setLegalizerInfo64bit() (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x10030db52)
#10 0x00000001053363f5 llvm::X86LegalizerInfo::X86LegalizerInfo(llvm::X86Subtarget const&, llvm::X86TargetMachine const&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x10030c3f5)
#11 0x0000000105381ace llvm::X86Subtarget::X86Subtarget(llvm::Triple const&, llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::X86TargetMachine const&, llvm::MaybeAlign, unsigned int, unsigned int) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x100357ace)
#12 0x0000000105382e50 llvm::X86TargetMachine::getSubtargetImpl(llvm::Function const&) const (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x100358e50)
#13 0x0000000105382fe6 llvm::X86TargetMachine::getTargetTransformInfo(llvm::Function const&) const (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x100358fe6)
#14 0x000000010816e2a3 std::__1::__function::__func<llvm::TargetMachine::getTargetIRAnalysis() const::$_3, std::__1::allocator<llvm::TargetMachine::getTargetIRAnalysis() const::$_3>, llvm::TargetTransformInfo (llvm::Function const&)>::operator()(llvm::Function const&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x1031442a3)
#15 0x0000000105ce54e8 llvm::TargetIRAnalysis::run(llvm::Function const&, llvm::AnalysisManager<llvm::Function>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x100cbb4e8)
#16 0x00000001081059b2 llvm::detail::AnalysisPassModel<llvm::Function, llvm::TargetIRAnalysis, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>::Invalidator>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x1030db9b2)
#17 0x000000010641b806 llvm::AnalysisManager<llvm::Function>::getResultImpl(llvm::AnalysisKey*, llvm::Function&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x1013f1806)
#18 0x0000000106c69ee2 llvm::SimplifyCFGPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x101c3fee2)
#19 0x000000010811b572 llvm::detail::PassModel<llvm::Function, llvm::SimplifyCFGPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x1030f1572)
#20 0x00000001064184b9 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x1013ee4b9)
#21 0x000000010718ebe2 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x102164be2)
#22 0x000000010641d239 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x1013f3239)
#23 0x0000000107190dc2 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x102166dc2)
#24 0x0000000106417169 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x1013ed169)
#25 0x0000000107188090 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>&, std::__1::unique_ptr<llvm::ToolOutputFile, std::__1::default_delete<llvm::ToolOutputFile>>&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x10215e090)
#26 0x0000000107181649 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x102157649)
#27 0x00000001075a0fd2 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x102576fd2)
#28 0x00000001089e8374 clang::ParseAST(clang::Sema&, bool, bool) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x1039be374)
#29 0x000000010799d963 clang::FrontendAction::Execute() (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x102973963)
#30 0x0000000107904159 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x1028da159)
#31 0x0000000107a2a860 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x102a00860)
#32 0x0000000105038b62 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x10000eb62)
#33 0x0000000105032e05 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x100008e05)
#34 0x000000010503212d clang_main(int, char**, llvm::ToolContext const&) (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x10000812d)
#35 0x00000001050447a4 main (/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/bin/clang-17+0x10001a7a4)

edit: seems like this already got reverted

tschuett added a comment.EditedMay 16 2023, 8:32 AM

It was reverted. There is an assert in legalFor.

@tschuett What's happening with fixing this? It looks easier than the POPCNT/LZCNT cases and still doesn't seem to work :(

@tschuett What's happening with fixing this? It looks easier than the POPCNT/LZCNT cases and still doesn't seem to work :(

I will do that soonish.