[all-commits] [llvm/llvm-project] 89e25a: [Transforms][LICM] A test case for the upcoming fi...

pawosm-arm via All-commits all-commits at lists.llvm.org
Tue Aug 1 08:43:05 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 89e25a3d6527f1a9a568384f0a07200c4ce59518
      https://github.com/llvm/llvm-project/commit/89e25a3d6527f1a9a568384f0a07200c4ce59518
  Author: Paul Osmialowski <pawel.osmialowski at arm.com>
  Date:   2023-08-01 (Tue, 01 Aug 2023)

  Changed paths:
    A llvm/test/Transforms/LICM/expr-reassociate.ll

  Log Message:
  -----------
  [Transforms][LICM] A test case for the upcoming fix D152281 for the issue with reassociation profitability

This commit introduces a test for the upcoming change addressing
the following issue: https://github.com/llvm/llvm-project/issues/62736

Reviewed By: qcolombet

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


  Commit: 8698d56d996a72b6ea87d751ec644c9c611717e2
      https://github.com/llvm/llvm-project/commit/8698d56d996a72b6ea87d751ec644c9c611717e2
  Author: Paul Osmialowski <pawel.osmialowski at arm.com>
  Date:   2023-08-01 (Tue, 01 Aug 2023)

  Changed paths:
    M llvm/lib/Transforms/Scalar/LICM.cpp
    M llvm/test/Transforms/LICM/expr-reassociate.ll

  Log Message:
  -----------
  [Transforms][LICM] Add the ability to undo unprofitable reassociation

Consider the following piece of code:

```
void innermost_loop(int i, double d1, double d2, double delta, int n, double cells[n])
{
  int j;
  const double d1d = d1 * delta;
  const double d2d = d2 * delta;

  for (j = 0; j <= i; j++)
    cells[j] = d1d * cells[j + 1] + d2d * cells[j];
}
```

When compiling at -Ofast level, after the "Reassociate expressions"
pass, this code is transformed into an equivalent of:

```
  int j;

  for (j = 0; j <= i; j++)
    cells[j] = (d1 * cells[j + 1] + d2 * cells[j]) * delta;
```

Effectively, the computation of those loop invariants isn't done
before the loop anymore, we have one extra multiplication on each
loop iteration instead. Sadly, this results in a significant
performance hit.

Similarly, specifically crafted user code will also experience
inability to hoist those invariants.

This patch is solving this issue by adding the ability to undo such
reassociation into the LICM pass. Note that for doing such
transformation this pass requires the same conditions as the
"Reassociate expressions" pass, namely, the involved binary operators
must have the reassociations allowed (e.g. by specifying the `fast`
attribute) and they must have single use only.

Some parts of this patch were suggested by Nikita Popov.

Reviewed By: huntergr, nikic, paulwalker-arm

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


Compare: https://github.com/llvm/llvm-project/compare/ee2168a34b04...8698d56d996a


More information about the All-commits mailing list