[GlobalISel] [X86] unable to legalize instruction


Can someone please let me know if I can expect GlobalISel to be functional for x86/x86-64 targets?

$ uname -a

Darwin 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64

Following is the command I used that resulted in an error :

~/github/build/llvm/Debug/bin/llc -global-isel -O0 simple_foo.ll

LLVM ERROR: unable to legalize instruction (in function: foo)

llc without the -global-isel option works fine.

I built clang/llc using the sources with the following tips:


761e543ac73 (HEAD → master, origin/master, origin/HEAD) [Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).


9563977e8b (HEAD → master, origin/master, origin/HEAD) [X86] Add support for ‘amdfam17h’ to __builtin_cpu_is to match gcc.



global-isel for x86 is still very much a work in progress. What was the content for simple_foo.ll?

Thanks for your quick reply.

Here its is:

I believe if you pass(iirc) -pass-remarks-missed=“gisel-*”, it’ll print the instruction it failed to legalize.

Sorry for the late follow-up.

Here is the output with the suggested option:

$ llc -global-isel -pass-remarks-missed=“gisel-*” simple_foo.ll

LLVM ERROR: unable to legalize instruction: %vreg17(s32) = G_SDIV %vreg15, %vreg16; (in function: foo)

Thanks for any help/suggestions.

Hi ,

Currently GobalIsel like FastIsel designed to use fallback to DAGIsel in case of failure.

You can use -global-isel-abort=2 option.

llc -global-isel -pass-remarks-missed=“gisel-*” -global-isel-abort=2 simple_foo.ll



Thank you very much for your reply. That helped.

I spent a little bit of time debugging the failure. It appears that X86LegalizerInfo does not (yet?) set up the required actions and tables for the opcode G_SDIV. I have not looked at GlobalISel phase earlier, but am curious to learn of the reasons for G_SDIV not being supported, yet. Are there any pointers that give some background? Of course, I hope to continue to dig irrespectively (albeit slowly :-)).

Thanks again!


The x86 IDIV instruction is a bit unusual; it actually has three register inputs. DAG ISel custom-lowers it; GlobalISel probably needs to do the same.