[all-commits] [llvm/llvm-project] 467b1f: [SimplifyCFG] Allow hoisting terminators only with...

Florian Hahn via All-commits all-commits at lists.llvm.org
Tue Apr 13 02:34:09 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 467b1f1cd2f2774714ce59919702c3963914b6a8
      https://github.com/llvm/llvm-project/commit/467b1f1cd2f2774714ce59919702c3963914b6a8
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2021-04-13 (Tue, 13 Apr 2021)

  Changed paths:
    M llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    M llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-required-for-vectorization.ll
    M llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll

  Log Message:
  -----------
  [SimplifyCFG] Allow hoisting terminators only with HoistCommonInsts=false.

As a side-effect of the change to default HoistCommonInsts to false
early in the pipeline, we fail to convert conditional branch & phis to
selects early on, which prevents vectorization for loops that contain
conditional branches that effectively are selects (or if the loop gets
vectorized, it will get vectorized very inefficiently).

This patch updates SimplifyCFG to perform hoisting if the only
instruction in both BBs is an equal branch. In this case, the only
additional instructions are selects for phis, which should be cheap.

Even though we perform hoisting, the benefits of this kind of hoisting
should by far outweigh the negatives.

For example, the loop in the code below will not get vectorized on
AArch64 with the current default, but will with the patch. This is a
fundamental pattern we should definitely vectorize. Besides that, I
think the select variants should be easier to use for reasoning across
other passes as well.

https://clang.godbolt.org/z/sbjd8Wshx

```
double clamp(double v) {
  if (v < 0.0)
    return 0.0;
  if (v > 6.0)
    return 6.0;
  return v;
}

void loop(double* X, double *Y) {
  for (unsigned i = 0; i < 20000; i++) {
    X[i] = clamp(Y[i]);
  }
}
```

Reviewed By: lebedev.ri

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




More information about the All-commits mailing list