Skip to content

Commit

Permalink
[llvm] Fix region simplification bug (NVIDIA#1889)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmhowe23 authored Jul 5, 2024
1 parent 977b283 commit a0b8a1d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docker/build/devdeps.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends git \
ADD ./tpls/customizations/llvm/llvm_pr71968_mod.diff /
RUN cd /llvm-project && git apply /llvm_pr71968_mod.diff && rm /llvm_pr71968_mod.diff

# Apply customization for https://github.com/NVIDIA/cuda-quantum/issues/1799
ADD ./tpls/customizations/llvm/fix_region_simplification.diff /
RUN cd /llvm-project && git apply /fix_region_simplification.diff && rm /fix_region_simplification.diff

# Build the the LLVM libraries and compiler toolchain needed to build CUDA-Q;
# The safest option to avoid any compatibility issues is to build an application using these libraries
# with the same compiler toolchain that the libraries were compiled with.
Expand Down
20 changes: 20 additions & 0 deletions tpls/customizations/llvm/fix_region_simplification.diff
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)

0 comments on commit a0b8a1d

Please sign in to comment.