This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 41d3168ea0 [FIX][LLVM] Preserve physical-root alignment on outlined 
aliases (#20577)
41d3168ea0 is described below

commit 41d3168ea0e63367b2636f1e7779889f585393ed
Author: Tianqi Chen <[email protected]>
AuthorDate: Tue Oct 6 21:35:02 2026 -0400

    [FIX][LLVM] Preserve physical-root alignment on outlined aliases (#20577)
    
    Resolve captured tensor aliases to their physical root when attaching
    known alignment to outlined compute-function parameters. Preserve
    incoming alignment facts inside each helper and restore the caller's
    facts afterward, so helper-local assumptions cannot strengthen later
    calls. Captured variables and pointer values remain unchanged.
---
 src/target/llvm/codegen_cpu.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/target/llvm/codegen_cpu.cc b/src/target/llvm/codegen_cpu.cc
index 35f1260569..7ec79f6672 100644
--- a/src/target/llvm/codegen_cpu.cc
+++ b/src/target/llvm/codegen_cpu.cc
@@ -515,6 +515,8 @@ void CodeGenCPU::CreateComputeScope(const RegionStmtNode* 
op) {
     explicit ComputeScopeStates(CodeGenCPU* parent) : parent_(parent) {}
 
     void EnterWithScope() {
+      // Inherit caller alignment facts without exporting helper-local 
assumptions.
+      alloc_storage_info_ = parent_->alloc_storage_info_;
       std::swap(function_, parent_->function_);
       std::swap(analyzer_, parent_->analyzer_);
       std::swap(var_map_, parent_->var_map_);
@@ -523,6 +525,7 @@ void CodeGenCPU::CreateComputeScope(const RegionStmtNode* 
op) {
     }
 
     void ExitWithScope() {
+      std::swap(alloc_storage_info_, parent_->alloc_storage_info_);
       std::swap(function_, parent_->function_);
       std::swap(analyzer_, parent_->analyzer_);
       std::swap(var_map_, parent_->var_map_);
@@ -533,6 +536,7 @@ void CodeGenCPU::CreateComputeScope(const RegionStmtNode* 
op) {
     llvm::Function* function_{nullptr};
     llvm::DISubprogram* di_subprogram_{nullptr};
     std::unordered_map<const VarNode*, llvm::Value*> var_map_;
+    std::unordered_map<const VarNode*, StorageInfo> alloc_storage_info_;
     std::vector<std::pair<llvm::BasicBlock*, llvm::BasicBlock*>> 
loop_frame_jump_tgts_;
     sym::Analyzer analyzer_{sym::Analyzer()};
     CodeGenCPU* parent_;
@@ -580,8 +584,8 @@ void CodeGenCPU::CreateComputeScope(const RegionStmtNode* 
op) {
       // always not inline compute function to make the code structure clean
       fcompute->addFnAttr(llvm::Attribute::NoInline);
     }
-    // Add alignment attribute if needed.
-    auto f = alloc_storage_info_.find(var.get());
+    // Alignment facts are shared by aliases of the same physical pointer.
+    auto f = alloc_storage_info_.find(GetBufferPhysicalRoot(var.get()));
     if (f != alloc_storage_info_.end()) {
       unsigned align = f->second.alignment;
       if (align > 1) {

Reply via email to