This is an archive of the discontinued LLVM Phabricator instance.

[fastregalloc] Fix bug when there is no register class.
AbandonedPublic

Authored by LuoYuanke on Jun 23 2022, 6:02 AM.

Details

Summary

In global Isel there may be no register class for a virtual register. In
that case we can invoke MRI->getRegClass(). We should invoke
MRI->getRegClassOrNull() instead and check if it returns nullptr.

Diff Detail

Event Timeline

LuoYuanke created this revision.Jun 23 2022, 6:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2022, 6:02 AM
LuoYuanke requested review of this revision.Jun 23 2022, 6:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2022, 6:02 AM

I can confirm this fixes the reproducer I posted on https://reviews.llvm.org/D126771.

arsenm requested changes to this revision.Jun 23 2022, 6:14 AM
arsenm added inline comments.
llvm/lib/CodeGen/RegAllocFast.cpp
307–310

This should not happen. This is a bug in x86 globalisel. Virtual registers without a class should not get past the selector. The verifier should catch this

This revision now requires changes to proceed.Jun 23 2022, 6:14 AM
LuoYuanke added inline comments.Jun 23 2022, 6:18 AM
llvm/lib/CodeGen/RegAllocFast.cpp
307–310

I'm not familiar with globalisel, but there is no harm for this patch. It just trigger the bug of globalisel. Can we land it first to let the lit test pass? We can debug and create another patch for globalisel if there is a bug in it.

LuoYuanke added inline comments.Jun 23 2022, 6:39 AM
llvm/lib/CodeGen/RegAllocFast.cpp
307–310

We can't trigger the bug with -verify-machineinstrs. There may be a bug in handling DBG_VALUE in globalisel.
DBG_VALUE %0:gpr, $noreg, !"argc", !DIExpression(), debug-location !19; foo.c:11:14 line no:11

However I think it is irrelevant to this patch.

arsenm added inline comments.Jun 23 2022, 6:42 AM
llvm/lib/CodeGen/RegAllocFast.cpp
307–310

No, this is a hack. The virtual register here should have been constrained to a real class

LuoYuanke added inline comments.Jun 23 2022, 6:49 AM
llvm/lib/CodeGen/RegAllocFast.cpp
307–310

That's the bug of globalisel, but we need more time to root cause it and fix it. Here we just avoid triggerring the bug and don't block others' work. When globalisel bug is fixed we can change back to getRegClass(). What do you think?

LuoYuanke added inline comments.Jun 23 2022, 6:51 AM
llvm/lib/CodeGen/RegAllocFast.cpp
307–310

How about add "FIXME" for the patch?

MatzeB requested changes to this revision.Jun 23 2022, 8:11 AM

When there is a bug producing invalid IR then we better crash than hide it.

Are you sure your bot touble actually comes from GlobalIsel? While GIsel is unfinished and likely broken on x86 it also shouldn‘t be enabled anywhere except a few dedicated globalisel tests…

LuoYuanke abandoned this revision.Jun 23 2022, 7:24 PM