[clang] 468782c - [CIR] Scope Canonicalize/Simplify greedy rewrites to the body region (#234810)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 23 19:19:28 PDT 2026


Author: Bruno Cardoso Lopes
Date: 2026-10-23T19:19:22-07:00
New Revision: 468782c725d8f58ee11466b187bc3d7b0f7e3a98

URL: https://github.com/llvm/llvm-project/commit/468782c725d8f58ee11466b187bc3d7b0f7e3a98
DIFF: https://github.com/llvm/llvm-project/commit/468782c725d8f58ee11466b187bc3d7b0f7e3a98.diff

LOG: [CIR] Scope Canonicalize/Simplify greedy rewrites to the body region (#234810)

Pass a GreedyRewriteConfig scoped to the body region at the three
greedy-rewrite call sites (CIRCanonicalize, CIRSimplify twice) instead
of letting the driver search for the common ancestor of the collected
ops. The body region encloses the ancestor the driver would find, so
this only skips the search.

The wider scope can additionally simplify region ancestors the narrow
one would not reach, but every rewrite stays semantics-preserving.
Measured on the investigation branch: TosaProfileCompliance -fclangir
end to end drops from 118.3s to about 109s.

Added: 
    

Modified: 
    clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
    clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index b4890a1b5bf37..31fbdcecc4414 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
@@ -80,8 +80,11 @@ void CIRCanonicalizePass::runOnOperation() {
       ops.push_back(op);
   });
 
-  // Apply patterns.
-  if (applyOpPatternsGreedily(ops, std::move(patterns)).failed())
+  // Apply patterns. Scope the rewrite to the body region, which encloses
+  // the common ancestor the driver would otherwise search for.
+  GreedyRewriteConfig config;
+  config.setScope(&getOperation()->getRegion(0));
+  if (applyOpPatternsGreedily(ops, std::move(patterns), config).failed())
     signalPassFailure();
 }
 

diff  --git a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp
index fe358ba9b273d..26a71045aa865 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp
@@ -422,8 +422,11 @@ void CIRSimplifyPass::runOnOperation() {
       ops.push_back(op);
   });
 
-  // Apply patterns.
-  if (applyOpPatternsGreedily(ops, std::move(patterns)).failed())
+  // Apply patterns. Scope the rewrite to the body region, which encloses
+  // the common ancestor the driver would otherwise search for.
+  GreedyRewriteConfig config;
+  config.setScope(&getOperation()->getRegion(0));
+  if (applyOpPatternsGreedily(ops, std::move(patterns), config).failed())
     signalPassFailure();
 
   // SimplifyConstantLoad needs to query dominance information, which could be
@@ -441,7 +444,11 @@ void CIRSimplifyPass::runSimplifyConstantLoad() {
     if (isa<LoadOp>(op))
       ops.push_back(op);
   });
-  if (applyOpPatternsGreedily(ops, std::move(patterns)).failed())
+  // Scope the rewrite to the body region, which encloses the common
+  // ancestor the driver would otherwise search for.
+  GreedyRewriteConfig config;
+  config.setScope(&getOperation()->getRegion(0));
+  if (applyOpPatternsGreedily(ops, std::move(patterns), config).failed())
     signalPassFailure();
 }
 


        


More information about the cfe-commits mailing list