[all-commits] [llvm/llvm-project] 7360d6: [ARM][MachineOutliner] Do not overestimate LR live...

Momchil Velikov via All-commits all-commits at lists.llvm.org
Mon Nov 2 08:48:39 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 7360d6d921c67e92cc82635112e72fb2a59aacf4
      https://github.com/llvm/llvm-project/commit/7360d6d921c67e92cc82635112e72fb2a59aacf4
  Author: Momchil Velikov <momchil.velikov at arm.com>
  Date:   2020-11-02 (Mon, 02 Nov 2020)

  Changed paths:
    M llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
    A llvm/test/CodeGen/ARM/machine-outliner-return-1.ll
    A llvm/test/CodeGen/ARM/machine-outliner-return-2.ll

  Log Message:
  -----------
  [ARM][MachineOutliner] Do not overestimate LR liveness in return block

The `LiveRegUnits` utility (as well as `LivePhysRegs`) considers
callee-saved registers to be alive at the point after the return
instruction in a block. In the ARM backend, the `LR` register is
classified as callee-saved, which is not really correct (from an ARM
eABI or just common sense point of view).  These two conditions cause
the `MachineOutliner` to overestimate the liveness of `LR`, which
results in unnecessary saves/restores of `LR` around calls to outlined
sequences.  It also causes the `MachineVerifer` to crash in some
cases, because the save instruction reads a dead `LR`, for example
when the following program:

int h(int, int);

int f(int a, int b, int c, int d) {
  a = h(a + 1, b - 1);
  b = b + c;
  return 1 + (2 * a + b) * (c - d) / (a - b) * (c + d);
}

int g(int a, int b, int c, int d) {
  a = h(a - 1, b + 1);
  b = b + c;
  return 2 + (2 * a + b) * (c - d) / (a - b) * (c + d);
}

is compiled with `-target arm-eabi -march=armv7-m -Oz`.

This patch computes the liveness of `LR` in return blocks only, while
taking into account the few ARM instructions, which read `LR`, but
nevertheless the register is not mentioned (explicitly or implicitly)
in the instruction operands.

Differential Revision: https://reviews.llvm.org/D89189




More information about the All-commits mailing list