[X86] MoveImm flag for instructions


I had (naively?) expected that the instruction to move immediate to register or memory (such as MOV32mi, MOV32ri, MOV64mi32, MOV64ri, MOV64ri32) would be marked with the flag MCID::MovImm via the X86InstrInfo.td (and hence in the generated X86GenInstrInfo.inc).

I do not see that to be the case.

Can someone please tell me if my expectation is flawed? Is there a better/different way to determine to test for move immediate to register/memory instruction on X86 other that the existing interface MCID::isMoveImmediate()?



That flag is specifically used by the foldImmediate optimization in the Peephole pass. We don’t implement the TLI foldImmediate hook the peephole pass uses on x86 so we have no reason to set the flag on any instructions

What are you trying to do?

I am trying to categorize the machine instructions based on associated static (i.e., as encoded in .td file) machine description and the corresponding APIs.
I would like to perform appropriate actions based on the kind of instruction in a tool that I am working on.

For example, I’d like to distinguish between memop instructions involving immediate vs register. While it appears that I would be able to accomplish this by rummaging through the instruction operands, a combination of the flag(s) MayLoad/MayStore and MoveImm seemed attractive/clean/efficient(?), if the instruction description did indeed use the flags.

Hence the question.



I think even if we did use it, MoveImmediate is intended for instructions that move an immediate into a register rather than into memory. It’s supposed to indicate instructions that can be folded with the user of the register by changing the user to an immediate instruction. And it wouldn’t be set on an instruction like “addl $0, %eax” or “addl $0, (%ecx)” either since those aren’t moves.

For X86 you can try using “X86II::hasImm(MI.getDesc().TSFlags)” that’s what the encoder uses to determine if there’s an immediate to encode at the end of the instruction encoding.

Thanks for the explanation and the suggestion, Craig. I will try it out.