[all-commits] [llvm/llvm-project] 195de3: [MLIR][SCF] Fix nested if merging bug

William Moses via All-commits all-commits at lists.llvm.org
Mon Mar 21 08:42:40 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 195de3dd6c86f01956f2d1f87b2b7dd25f8c0aed
      https://github.com/llvm/llvm-project/commit/195de3dd6c86f01956f2d1f87b2b7dd25f8c0aed
  Author: William S. Moses <gh at wsmoses.com>
  Date:   2022-03-21 (Mon, 21 Mar 2022)

  Changed paths:
    M mlir/lib/Dialect/SCF/SCF.cpp
    M mlir/test/Dialect/SCF/canonicalize.mlir

  Log Message:
  -----------
  [MLIR][SCF] Fix nested if merging bug

The current nested if merging has a bug. Specifically, consider the following code:

```
    %r = scf.if %arg3 -> (i32) {
      scf.if %arg1 {
        "test.op"() : () -> ()
      }
      scf.yield %arg0 : i32
    } else {
      scf.yield %arg2 : i32
    }
```

When the above gets merged, it will become:
```
    %r = scf.if %arg3 && %arg1-> (i32) {
      "test.op"() : () -> ()
      scf.yield %arg0 : i32
    } else {
      scf.yield %arg2 : i32
    }
```

However, this means that when only %arg3 is true, we will incorrectly return %arg2 instead
of %arg0. This change updates the behavior of the pass to only enable nested if merging where
the outer yield contains only values from the inner if, or values defined outside of the if.

In the case of the latter, they can turned into a select of only the outer if condition, thus
maintaining correctness.

Reviewed By: ftynse

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




More information about the All-commits mailing list