forked from NVIDIA/cuda-quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm] Fix region simplification bug (NVIDIA#1889)
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
diff --git a/mlir/lib/Transforms/Utils/RegionUtils.cpp b/mlir/lib/Transforms/Utils/RegionUtils.cpp | ||
index 996588243..63ab385be 100644 | ||
--- a/mlir/lib/Transforms/Utils/RegionUtils.cpp | ||
+++ b/mlir/lib/Transforms/Utils/RegionUtils.cpp | ||
@@ -679,6 +679,15 @@ static LogicalResult mergeIdenticalBlocks(RewriterBase &rewriter, | ||
if (hasNonEmptyRegion) | ||
continue; | ||
|
||
+ // Don't allow merging if this block's arguments are used outside of the | ||
+ // original block. | ||
+ bool argHasExternalUsers = llvm::any_of( | ||
+ block->getArguments(), [block](mlir::BlockArgument &arg) { | ||
+ return arg.isUsedOutsideOfBlock(block); | ||
+ }); | ||
+ if (argHasExternalUsers) | ||
+ continue; | ||
+ | ||
// Try to add this block to an existing cluster. | ||
bool addedToCluster = false; | ||
for (auto &cluster : clusters) |