How to test an individual instruction?


I have implemented only ADD instruction for my target so far. How to test if it is generating the code that I am expecting? I saw the existing codegen lit tests for other targets and all of them were llvm IR instructions that was inside a function or main.

Is it even possible to test a single llvm instruction like add without having the function call and return support for the target?

If not, what is the best order of implementing the instructions so that each instruction could be tested as and when it is implemented?

Thanks a lot!

For globalisel you can test selection of a single instruction and sidestep the ABI lowering code with a MIR test. Generally you need at minimum the ABI handling implemented to write a meaningful IR test

1 Like

Thanks! How about writing a test just for add instruction for a backend that doesn’t use GlobalISel?


No, SelectionDAG can’t independently test pieces

1 Like

It’s for this reason that it’s normally best to start with

define void @foo() {
  ret void

as the first function to make work and only then start to add support for more complicated code generation.


Thank you both Matt and Jessica.

Yes, I too remember seeing a global instruction selection Youtube video where they recommend to implement the return instruction first.