[PATCH] D27193: MachineLoopInfo: add function findInductionRegister.

Quentin Colombet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 4 16:43:51 PST 2017


qcolombet added a comment.

Hi,

Thanks for your patience!

> What I also mean is that I don't want to have this in at all costs, or in other words, if we agree this patch is not going to help in any way then yes let's not waste time and abandon it.

In that case, I would suggest to have a generic (Machine)Analysis pass that computes all the IVs. The way I envision this is by injecting more semantic on the target instructions. Hal suggested in another review (I don't remember which one though), that we could do that with a single API looking like `bool TargetInstrInfo::isSimilarTo(const MachineInstr &MI, unsigned Opcode, SmallVectorImpl<MachineOperand *>& VRegs)`, where VRegs would contain the list of operands that matches Opcode behavior. We did not work out the details.
This gets possible thanks to GlobalISel that features generic opcodes that we can use as a reference (e.g., G_ADD, G_MUL, etc.).

The way we would use this API would look like:
// Check if this MI is an IV update of the form Def = Arg1 + Arg2.
SmallVector<MachineOperand *, 4> Opds;
if (TII->isSimilarTo(MI, TargetOpcode::G_ADD, Opds)) {

  MachineOperand *Def = Opds[0];
  MachineOperand *Arg1 = Opds[1]; 
  MachineOperand *Arg2 = Opds[2];
  // Check if the update is constant.
  if (Arg2.isImm() || (Arg2.isReg && TII->isSimilarTo(MRI.getUniqueDef(Arg2.getReg()), G_CONSTANT, [...]))
  [...]

}

Note: we may actually use something different than MachineOperand to represent similar construction but with no physical machine operand (e.g., `a = b << 1` is equivalent to `a = b * 2`, but we don't have a MachineOperand to convey this information).

The nice thing about this direction is that we may be able to extract the semantic of some target specific instructions directly form the ISel patterns. E.g., if we have a pattern (add src1, src2) -> (ADDXrr src1, src2), we could deduce automatically that ADDXrr is similar to G_ADD.

Anyhow, there is a lot of work to be there and there may be dragons on the path!

Cheers,
-Quentin


https://reviews.llvm.org/D27193





More information about the llvm-commits mailing list