Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ae44c20
[Feature] Implement Hoist Loop-Invariant If Pass
chengyupku Jan 28, 2026
3e5f6fe
Add tilelang semantics guide to programming guides (#1740)
LeiWang1999 Jan 28, 2026
9b9a100
Add CallNodeChecker to Loop Unswitching Pass and integrate tilelang c…
LeiWang1999 Jan 28, 2026
f64be56
lint fix
LeiWang1999 Jan 28, 2026
3cff414
lint fix
LeiWang1999 Jan 28, 2026
f9dfefa
Enhance Loop Unswitching Pass with Let Binding Support
LeiWang1999 Jan 29, 2026
c542090
fix
LeiWang1999 Jan 29, 2026
77d2bc8
lint fix
LeiWang1999 Jan 29, 2026
1f06094
Enhance Loop Unswitching with CallNode Exclusion Check
LeiWang1999 Jan 29, 2026
6ca70ed
Merge branch 'main' of https://github.com/tile-ai/tilelang into cheng…
LeiWang1999 Jan 29, 2026
56f3201
Update TVM subproject to latest commit and remove debug print stateme…
LeiWang1999 Jan 29, 2026
117e6d4
Add support for disabling loop unswitching optimization
LeiWang1999 Jan 31, 2026
5e0ca63
Merge branch 'main' of https://github.com/tile-ai/tilelang
LeiWang1999 May 8, 2026
512c995
update tvm
LeiWang1999 May 13, 2026
5917853
Refactor: Update TileLang to use tirx instead of tir
LeiWang1999 May 13, 2026
3cb4d45
pass fix
LeiWang1999 May 17, 2026
8d962c1
Update submodule 'tvm' to latest commit f24c7b19
LeiWang1999 May 18, 2026
8ee736f
Apply formatting fixes
LeiWang1999 May 18, 2026
468c17c
Merge branch 'main' of https://github.com/tile-ai/tilelang into refac…
LeiWang1999 May 18, 2026
f13add9
Update CMakeLists.txt to set HIDE_PRIVATE_SYMBOLS for TileLang and mo…
LeiWang1999 May 18, 2026
2be9ca2
Refactor CMakeLists.txt and kernel_cache.py to update target names an…
LeiWang1999 May 18, 2026
008d88c
Update repair-wheel-command in pyproject.toml to exclude libz3.so wit…
LeiWang1999 May 18, 2026
3869d1d
Fix macOS Z3 dylib lookup
LeiWang1999 May 18, 2026
f4274ab
Move macOS Z3 install-name fix to install step
LeiWang1999 May 18, 2026
0c11d0b
Update TVM submodule for runtime import fix
LeiWang1999 May 18, 2026
0b0674d
Update ROCm backend for TVM module factory changes
LeiWang1999 May 18, 2026
32e5ef2
Merge branch 'main' of https://github.com/tile-ai/tilelang into refac…
LeiWang1999 May 18, 2026
c9346d7
Merge branch 'main' of https://github.com/tile-ai/tilelang into refac…
LeiWang1999 May 18, 2026
fe39b74
Fix build-tree Z3 runtime lookup
LeiWang1999 May 18, 2026
0311110
Merge branch 'main' of https://github.com/tile-ai/tilelang into refac…
LeiWang1999 May 18, 2026
1919c13
Fix macOS build-tree Z3 lookup
LeiWang1999 May 18, 2026
130260c
Support legacy target option strings
LeiWang1999 May 18, 2026
458475f
Normalize CUDA target in transform test
LeiWang1999 May 18, 2026
1ee3e74
Qualify Metal stream FFI lookup
LeiWang1999 May 18, 2026
a49e62b
Fix PyPI Z3 packaging links
LeiWang1999 May 18, 2026
acc01a3
Update TVM for Windows DLL lookup
LeiWang1999 May 18, 2026
58cf4ca
Register Windows dependency DLL directories
LeiWang1999 May 18, 2026
e894033
Bump tvm-ffi to match tirx
oraluben May 18, 2026
e3f8593
Merge branch 'main' of https://github.com/tile-ai/tilelang into refac…
LeiWang1999 May 19, 2026
6ab406b
tvm update
LeiWang1999 May 19, 2026
9baf1dc
Merge remote-tracking branch 'lei/refactor/tirx-tvm-update' into refa…
LeiWang1999 May 19, 2026
828abdb
Apply lint fixes
LeiWang1999 May 19, 2026
9078f39
Enhance reduction operations with support for nan propagation and vec…
LeiWang1999 May 19, 2026
913726e
Merge branch 'main' of https://github.com/tile-ai/tilelang into refac…
LeiWang1999 May 19, 2026
1620cb6
Refactor ReduceLowerer: Remove unnecessary buffer allocation logic fo…
LeiWang1999 May 19, 2026
98d391a
Merge branch 'main' of https://github.com/tile-ai/tilelang into refac…
LeiWang1999 May 20, 2026
3805846
Normalize PyPI Z3 dylib before linking
LeiWang1999 May 20, 2026
02b259a
Drop legacy target option string support
LeiWang1999 May 20, 2026
4c804bc
Merge branch 'main' of https://github.com/tile-ai/tilelang into refac…
LeiWang1999 May 20, 2026
377aa10
Merge branch 'main' of https://github.com/tile-ai/tilelang into refac…
LeiWang1999 May 20, 2026
7b2bae0
Fix type reference for barrier annotations in CUDA copy operations. U…
LeiWang1999 May 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enhance Loop Unswitching with CallNode Exclusion Check
- Added CallCheckerExcludingIf class to ensure function calls outside of hoisted if statements are identified, preventing potential synchronization issues during loop unswitching.
- Updated loop unswitching logic to incorporate the new call checker, enhancing safety and correctness.
- Integrated debug print statements in OptimizeForTarget to visualize module state before and after loop unswitching.
- Disabled tilelang cache in the benchmark script for improved performance.
  • Loading branch information
LeiWang1999 committed Jan 29, 2026
commit 1f06094dcb17b6e32f4a677229017bd0e4faddf2
45 changes: 45 additions & 0 deletions src/transform/loop_unswitching.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,36 @@ class CallNodeChecker : public ExprVisitor {
}
};

/*!
* \brief Check if a statement contains any CallNode, excluding a specific If
*
* Loop unswitching is unsafe when there are function calls OUTSIDE the
* hoisted if statement, because those calls (originally executed by all
* threads together) would be split into different code paths after
* unswitching, potentially breaking synchronization semantics.
*
* Calls INSIDE the if are safe because they were already conditionally
* executed before unswitching.
*/
class CallCheckerExcludingIf : public StmtExprVisitor {
public:
bool has_call = false;
const IfThenElseNode *excluded_if = nullptr;

void VisitStmt_(const IfThenElseNode *op) final {
if (op == excluded_if) {
// Skip the interior of the excluded if statement
return;
}
StmtExprVisitor::VisitStmt_(op);
}

void VisitExpr_(const CallNode *op) final {
has_call = true;
// No need to continue once we find a call
}
};

/*!
* \brief Check if condition or any Let-bound variable it uses depends on loop
* var
Expand Down Expand Up @@ -297,6 +327,21 @@ class LoopUnswitcher : public StmtExprMutator {
op->thread_binding, op->annotations);
}

// Check if there are any function calls OUTSIDE the hoisted if statement.
// Calls outside the if are executed by all threads together; unswitching
// would split them into different code paths, breaking synchronization.
// Calls inside the if are already conditionally executed, so they're safe.
CallCheckerExcludingIf call_checker;
call_checker.excluded_if = finder.found;
call_checker(body);
if (call_checker.has_call) {
if (body.same_as(op->body)) {
return ffi::GetRef<Stmt>(op);
}
return For(op->loop_var, op->min, op->extent, op->kind, body,
op->thread_binding, op->annotations);
}

// Unswitch: create two loop versions
const IfThenElseNode *if_node = finder.found;

Expand Down
4 changes: 4 additions & 0 deletions tilelang/engine/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ def OptimizeForTarget(mod: IRModule, target: Target) -> IRModule:
mod = tir.transform.Simplify()(mod)
mod = tilelang.transform.VectorizeLoop(enable_vectorize=allow_vectorize(pass_ctx=pass_ctx))(mod)
mod = tilelang.transform.StorageRewrite()(mod)
print("Before StorageRewrite")
print(mod)
mod = tilelang.transform.LoopUnswitching()(mod)
print("After LoopUnswitching")
print(mod)
mod = tilelang.transform.UnrollLoop()(mod)
mod = tir.transform.RenormalizeSplitPattern()(mod)
mod = tir.transform.Simplify()(mod)
Expand Down