[Mlir-commits] [mlir] [MLIR][SCF] Speed up ConditionPropagation (PR #166080)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Nov 2 10:26:37 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- mlir/lib/Dialect/SCF/IR/SCF.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 2d5a0052d..af02fdbc5 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -2565,14 +2565,11 @@ struct ConvertTrivialIfToSelect : public OpRewritePattern<IfOp> {
 struct ConditionPropagation : public OpRewritePattern<IfOp> {
   using OpRewritePattern<IfOp>::OpRewritePattern;
 
-  enum class Parent {
-    Then,
-    Else,
-    None
-  };
+  enum class Parent { Then, Else, None };
 
-  static Parent getParentType(Region *toCheck, IfOp op, DenseMap<Region*, Parent> &cache) {
-    SmallVector<Region*> seen;
+  static Parent getParentType(Region *toCheck, IfOp op,
+                              DenseMap<Region *, Parent> &cache) {
+    SmallVector<Region *> seen;
     while (toCheck) {
       auto found = cache.find(toCheck);
       if (found != cache.end()) {
@@ -2615,11 +2612,11 @@ struct ConditionPropagation : public OpRewritePattern<IfOp> {
     Value constantTrue = nullptr;
     Value constantFalse = nullptr;
 
-    DenseMap<Region*, Parent> regionCache;
+    DenseMap<Region *, Parent> regionCache;
     for (OpOperand &use :
          llvm::make_early_inc_range(op.getCondition().getUses())) {
-      switch(getParentType(use.getOwner()->getParentRegion(), op, cache)) {
-      case Parent::Then:{
+      switch (getParentType(use.getOwner()->getParentRegion(), op, cache)) {
+      case Parent::Then: {
         changed = true;
 
         if (!constantTrue)
@@ -2630,7 +2627,7 @@ struct ConditionPropagation : public OpRewritePattern<IfOp> {
                                  [&]() { use.set(constantTrue); });
         break;
       }
-      case Parent::Else:{
+      case Parent::Else: {
         changed = true;
 
         if (!constantFalse)

``````````

</details>


https://github.com/llvm/llvm-project/pull/166080


More information about the Mlir-commits mailing list