Please expose predicates to MachineVerifier

Could we expose predicates defined in the target file to the MachineVerifier? We use BuildMI() to create many instructions after ISEL, but the predicates are not being checked at this point. Thus, I could forget to check the target and build an instruction that is illegal for a specific configuration. In such a case it would be nice if the MachineVerifier could detect this for me.

Example predicate IsCore8 usage:

def ADDx: BINOP<…>, Requires<[IsCore8]>;

let Predicates=[IsCore8] in {

def : SUBX: BINOP<…>;


The predicates are encoded into the targets GenDAGIsel file but not anywhere else that I can find:

OPC_CheckPatternPredicate, 4, // (Subtarget.isCore8())


There’s already an existing hook for adding target-specific verification logic in the target’s TargetInstrInfo::verifyInstruction. That doesn’t really scale to checking that you’re using an appropriate subtarget for every instruction, though. (You could, but it would involve a lot of redundant hand-written code for many targets.)

We can’t really use any of the existing code generated by TableGen to perform the checks in question; I don’t think we currently expose the relevant predicates in any useful way. But it would probably be appropriate to extend TableGen to generate code for those checks, I think. It would probably also require some modifications to the TableGen files themselves; currently, at least for some targets, we use Requires predicates on instructions which are legal, but we don’t want the TableGen’ed isel to select for some reason.


Hi Mark!

Downstream I've added some support for our target (in this example called Qwerty) like this.

In utils/TableGen/InstrInfoEmitter.cpp I've added:

And as Eli already pointed out, some extra attention might be needed for this kind of EmitPredicateVerifier hack to work for any target.

In our downstream target we have separated all instruction definitions from the patterns that selects the instructions. So I can use Requires<> tp specify the predicates for when a specific instruction is valid when defining an instruction. And then I can use totally different predicates for the Pat<> rules that selects the instructions.

For a target that is mixing things up by having selection patterns included into the instruction definitions it might be more complicated if the backend is allowed to select the same instruction based on other predicates outside of the ISelDAG.