Skip to content

[mlir] Recover the behavior of SliceAnaylsis for llvm-project@6a8dde04a07 #142076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025

Conversation

hanhanW
Copy link
Contributor

@hanhanW hanhanW commented May 30, 2025

In 6a8dde0, it changes the method to return LogicalFailure, so callers can handle the failure instead of crashing, if I read the intention correctly. However, it changes the behavior of the implementation; it breaks several integratino tests in downstream projects (e.g., IREE).

Before the change, processValue does not treat it as a failure if the check below TODO has a false condition. However, with the new change, it starts treating it as a failure.

The revision updates the final else branch (i.e., llvm_unreachable line) to return a failure, and return success at the end; the behavior is recovered.

auto processValue = [&](Value value) {
  if (auto *definingOp = value.getDefiningOp()) {
    if (backwardSlice->count(definingOp) == 0)
      getBackwardSliceImpl(definingOp, backwardSlice, options);
  } else if (auto blockArg = dyn_cast<BlockArgument>(value)) {
    if (options.omitBlockArguments)
      return;

    Block *block = blockArg.getOwner();
    Operation *parentOp = block->getParentOp();
    // TODO: determine whether we want to recurse backward into the other
    // blocks of parentOp, which are not technically backward unless they flow
    // into us. For now, just bail.
    if (parentOp && backwardSlice->count(parentOp) == 0) {
      assert(parentOp->getNumRegions() == 1 &&
             llvm::hasSingleElement(parentOp->getRegion(0).getBlocks()));
      getBackwardSliceImpl(parentOp, backwardSlice, options);

    }
  } else {
    llvm_unreachable("No definingOp and not a block argument.");
  }

No additional tests are added, like the previous commit. This revision is mostly a post-fix for 6a8dde0

Co-authored-by: Ian Wood [email protected]

In llvm@6a8dde0,
it changes the method to return LogicalFailure, so callers can handle
the failure instead of crashing, if I read the intention correctly.
However, it changes the behavior of the implementation.

Before the change, processValue does not treat it as a failure if the
check below TODO has a false condition. However, with the new change, it
starts treating it as a failure.

The revision updates the final `else` branch to return a failure, and
return success at the end; the behavior is recovered.

```cpp
auto processValue = [&](Value value) {
  if (auto *definingOp = value.getDefiningOp()) {
    if (backwardSlice->count(definingOp) == 0)
      getBackwardSliceImpl(definingOp, backwardSlice, options);
  } else if (auto blockArg = dyn_cast<BlockArgument>(value)) {
    if (options.omitBlockArguments)
      return;

    Block *block = blockArg.getOwner();
    Operation *parentOp = block->getParentOp();
    // TODO: determine whether we want to recurse backward into the other
    // blocks of parentOp, which are not technically backward unless they flow
    // into us. For now, just bail.
    if (parentOp && backwardSlice->count(parentOp) == 0) {
      assert(parentOp->getNumRegions() == 1 &&
             llvm::hasSingleElement(parentOp->getRegion(0).getBlocks()));
      getBackwardSliceImpl(parentOp, backwardSlice, options);

    }
  } else {
    llvm_unreachable("No definingOp and not a block argument.");
  }
```

No additional tests are added like the previous commit. This revision is
mostly a post-fix for llvm@6a8dde0

Signed-off-by: hanhanW <[email protected]>
@hanhanW hanhanW requested review from wsmoses, ftynse and joker-eph May 30, 2025 01:36
@llvmbot llvmbot added the mlir label May 30, 2025
@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/pr-subscribers-mlir

Author: Han-Chung Wang (hanhanW)

Changes

In 6a8dde0, it changes the method to return LogicalFailure, so callers can handle the failure instead of crashing, if I read the intention correctly. However, it changes the behavior of the implementation.

Before the change, processValue does not treat it as a failure if the check below TODO has a false condition. However, with the new change, it starts treating it as a failure.

The revision updates the final else branch to return a failure, and return success at the end; the behavior is recovered.

auto processValue = [&amp;](Value value) {
  if (auto *definingOp = value.getDefiningOp()) {
    if (backwardSlice-&gt;count(definingOp) == 0)
      getBackwardSliceImpl(definingOp, backwardSlice, options);
  } else if (auto blockArg = dyn_cast&lt;BlockArgument&gt;(value)) {
    if (options.omitBlockArguments)
      return;

    Block *block = blockArg.getOwner();
    Operation *parentOp = block-&gt;getParentOp();
    // TODO: determine whether we want to recurse backward into the other
    // blocks of parentOp, which are not technically backward unless they flow
    // into us. For now, just bail.
    if (parentOp &amp;&amp; backwardSlice-&gt;count(parentOp) == 0) {
      assert(parentOp-&gt;getNumRegions() == 1 &amp;&amp;
             llvm::hasSingleElement(parentOp-&gt;getRegion(0).getBlocks()));
      getBackwardSliceImpl(parentOp, backwardSlice, options);

    }
  } else {
    llvm_unreachable("No definingOp and not a block argument.");
  }

No additional tests are added, like the previous commit. This revision is mostly a post-fix for 6a8dde0


Full diff: https://github.com/llvm/llvm-project/pull/142076.diff

1 Files Affected:

  • (modified) mlir/lib/Analysis/SliceAnalysis.cpp (+3-1)
diff --git a/mlir/lib/Analysis/SliceAnalysis.cpp b/mlir/lib/Analysis/SliceAnalysis.cpp
index c4eda71c42f3e..4cdf47a405c01 100644
--- a/mlir/lib/Analysis/SliceAnalysis.cpp
+++ b/mlir/lib/Analysis/SliceAnalysis.cpp
@@ -111,8 +111,10 @@ static LogicalResult getBackwardSliceImpl(Operation *op,
           return getBackwardSliceImpl(parentOp, backwardSlice, options);
         }
       }
+    } else {
+      return failure();
     }
-    return failure();
+    return success();
   };
 
   bool succeeded = true;

@wsmoses
Copy link
Member

wsmoses commented May 30, 2025

yeah fair catch -- and yes that should've been a commit which didn't change behavior.

@hanhanW hanhanW merged commit 587d6fc into llvm:main May 30, 2025
11 of 12 checks passed
@hanhanW hanhanW deleted the backward-slice-fix branch May 30, 2025 02:18
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 30, 2025

LLVM Buildbot has detected a new failure on builder mlir-nvidia running on mlir-nvidia while building mlir at step 7 "test-build-check-mlir-build-only-check-mlir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/138/builds/13875

Here is the relevant piece of the build log for the reference
Step 7 (test-build-check-mlir-build-only-check-mlir) failure: test (failure)
******************** TEST 'MLIR :: Integration/GPU/CUDA/async.mlir' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/GPU/CUDA/async.mlir  | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt -gpu-kernel-outlining  | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt -pass-pipeline='builtin.module(gpu.module(strip-debuginfo,convert-gpu-to-nvvm),nvvm-attach-target)'  | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt -gpu-async-region -gpu-to-llvm -reconcile-unrealized-casts -gpu-module-to-binary="format=fatbin"  | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt -async-to-async-runtime -async-runtime-ref-counting  | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt -convert-async-to-llvm -convert-func-to-llvm -convert-arith-to-llvm -convert-cf-to-llvm -reconcile-unrealized-casts  | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-runner    --shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_cuda_runtime.so    --shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_async_runtime.so    --shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_runner_utils.so    --entry-point-result=void -O0  | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/GPU/CUDA/async.mlir
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/GPU/CUDA/async.mlir
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt -gpu-kernel-outlining
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt '-pass-pipeline=builtin.module(gpu.module(strip-debuginfo,convert-gpu-to-nvvm),nvvm-attach-target)'
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt -gpu-async-region -gpu-to-llvm -reconcile-unrealized-casts -gpu-module-to-binary=format=fatbin
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt -async-to-async-runtime -async-runtime-ref-counting
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt -convert-async-to-llvm -convert-func-to-llvm -convert-arith-to-llvm -convert-cf-to-llvm -reconcile-unrealized-casts
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-runner --shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_cuda_runtime.so --shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_async_runtime.so --shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_runner_utils.so --entry-point-result=void -O0
# .---command stderr------------
# | 'cuStreamWaitEvent(stream, event, 0)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# | 'cuEventDestroy(event)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# | 'cuStreamWaitEvent(stream, event, 0)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# | 'cuEventDestroy(event)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# | 'cuStreamWaitEvent(stream, event, 0)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# | 'cuStreamWaitEvent(stream, event, 0)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# | 'cuEventDestroy(event)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# | 'cuEventDestroy(event)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# | 'cuEventSynchronize(event)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# | 'cuEventDestroy(event)' failed with 'CUDA_ERROR_CONTEXT_IS_DESTROYED'
# `-----------------------------
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/GPU/CUDA/async.mlir
# .---command stderr------------
# | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/GPU/CUDA/async.mlir:68:12: error: CHECK: expected string not found in input
# |  // CHECK: [84, 84]
# |            ^
# | <stdin>:1:1: note: scanning from here
# | Unranked Memref base@ = 0x55a84fcc19e0 rank = 1 offset = 0 sizes = [2] strides = [1] data = 
# | ^
# | <stdin>:2:1: note: possible intended match here
# | [42, 42]
# | ^
# | 
# | Input file: <stdin>
# | Check file: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/GPU/CUDA/async.mlir
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             1: Unranked Memref base@ = 0x55a84fcc19e0 rank = 1 offset = 0 sizes = [2] strides = [1] data =  
# | check:68'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
# |             2: [42, 42] 
# | check:68'0     ~~~~~~~~~
# | check:68'1     ?         possible intended match
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented May 30, 2025

LLVM Buildbot has detected a new failure on builder premerge-monolithic-windows running on premerge-windows-1 while building mlir at step 5 "clean-build-dir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/35/builds/10510

Here is the relevant piece of the build log for the reference
Step 5 (clean-build-dir) failure: Delete failed. (failure)
Step 8 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'lit :: timeout-hang.py' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 13
not env -u FILECHECK_OPTS "C:\Python39\python.exe" C:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\utils\lit\lit.py -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt  --timeout=1 --param external=0 | "C:\Python39\python.exe" C:\ws\buildbot\premerge-monolithic-windows\build\utils\lit\tests\timeout-hang.py 1
# executed command: not env -u FILECHECK_OPTS 'C:\Python39\python.exe' 'C:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\utils\lit\lit.py' -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt --timeout=1 --param external=0
# .---command stderr------------
# | lit.py: C:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\utils\lit\lit\main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 1 seconds was requested on the command line. Forcing timeout to be 1 seconds.
# `-----------------------------
# executed command: 'C:\Python39\python.exe' 'C:\ws\buildbot\premerge-monolithic-windows\build\utils\lit\tests\timeout-hang.py' 1
# .---command stdout------------
# | Testing took as long or longer than timeout
# `-----------------------------
# error: command failed with exit status: 1

--

********************


@@ -111,8 +111,10 @@ static LogicalResult getBackwardSliceImpl(Operation *op,
return getBackwardSliceImpl(parentOp, backwardSlice, options);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this else return a failure? (to reflect the original assert?)

@wsmoses
Copy link
Member

wsmoses commented May 30, 2025

Yeah looking at this again this patch is wrong and indeed it should return a failure there

@wsmoses
Copy link
Member

wsmoses commented May 30, 2025

fix in #142223

sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…4a07 (llvm#142076)

In
llvm@6a8dde0,
it changes the method to return LogicalFailure, so callers can handle
the failure instead of crashing, if I read the intention correctly.
However, it changes the behavior of the implementation; it breaks
several integratino tests in downstream projects (e.g., IREE).

Before the change, processValue does not treat it as a failure if the
check below TODO has a false condition. However, with the new change, it
starts treating it as a failure.

The revision updates the final `else` branch (i.e., `llvm_unreachable`
line) to return a failure, and return success at the end; the behavior
is recovered.

```cpp
auto processValue = [&](Value value) {
  if (auto *definingOp = value.getDefiningOp()) {
    if (backwardSlice->count(definingOp) == 0)
      getBackwardSliceImpl(definingOp, backwardSlice, options);
  } else if (auto blockArg = dyn_cast<BlockArgument>(value)) {
    if (options.omitBlockArguments)
      return;

    Block *block = blockArg.getOwner();
    Operation *parentOp = block->getParentOp();
    // TODO: determine whether we want to recurse backward into the other
    // blocks of parentOp, which are not technically backward unless they flow
    // into us. For now, just bail.
    if (parentOp && backwardSlice->count(parentOp) == 0) {
      assert(parentOp->getNumRegions() == 1 &&
             llvm::hasSingleElement(parentOp->getRegion(0).getBlocks()));
      getBackwardSliceImpl(parentOp, backwardSlice, options);

    }
  } else {
    llvm_unreachable("No definingOp and not a block argument.");
  }
```

No additional tests are added, like the previous commit. This revision
is mostly a post-fix for
llvm@6a8dde0

Co-authored-by: Ian Wood <[email protected]>

Signed-off-by: hanhanW <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants