[PATCH] D101970: [X86FixupLEAs] Transform the sequence LEA/SUB to SUB/SUB

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 25 08:54:10 PDT 2021


Carrot added a comment.

In D101970#2779338 <https://reviews.llvm.org/D101970#2779338>, @davezarzycki wrote:

> Actually, it is more complicated, and you're right that it also can involve overflow. I'm not sure if this is a trivial optimization when dependent comparisons are involved.

The new changes in function searchALUInst exactly does this check.

  // X - (Y + Z) may generate different flags than (X - Y) - Z when there
  // is overflow. So we can't change the alu instruction if the flags
  // register is live.
  MachineBasicBlock::iterator NextI = std::next(CurInst);
  if (MBB.computeRegisterLiveness(TRI, X86::EFLAGS, NextI) !=
      MachineBasicBlock::LQR_Dead)
    return MachineBasicBlock::iterator();

If the flags of SUB/ADD is live, it will be used by following comparison or conditional branch or other instructions, we will give up the transformation.

In other words, only when the flags of the ALU instruction will not be used by following instructions (comparison or conditional branch), then we can do the transformation.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101970/new/

https://reviews.llvm.org/D101970



More information about the llvm-commits mailing list