Pull Request已成功合入, 合并人@ascend-robot
(感谢 hujiajun 的贡献)变更摘要
此 PR 修复了 PlanMemory 中向量函数(VF)inplace 复用的可达性分析缺陷。原先 VisitInplaceReuseReachable 会沿着同一 VF 调用内的可复用操作数跳转,导致虚假的 StoreOp/LoadOp 可达性传播,使得 IsReuseVFCall 错误地拒绝合法的 VF inplace 配对。修复方案:移除 VF 跳转逻辑,仅保留直接 use-def 链追踪(subview/collapse_shape/expand_shape);引入 Union-Find 结构,在 inplace 配对被实际采纳后才通过 unite() 传播可达性,而非提前推测传播;同时支持每个 op 的多个 VF inplace 配对,并按 gen buffer 大小降序贪心匹配。
主要改动
-
移除
VisitInplaceReuseReachable中的 VF 跳转逻辑:删除了对hivm::isVFCall(user)的检查及getInplaceReusableOperands迭代,现在仅沿memref.subview、memref.collapse_shape和memref.expand_shape追踪直接 use-def 链,避免在同 VF 调用内错误传播可达性。 -
新增 Union-Find 支持:在
InplaceReuseReachableMap中添加parent映射表、find()路径压缩查找和unite()合并方法;put()和get()在存取前先调用find()定位根节点;unite()在合并前将 killRoot 的可达性传播至 genRoot,确保可达性仅在实际采纳配对后传播。 -
重构
GenerateInplaceList配对策略:移除原先只选单个最优 VF 配对的bestVFInplacePair机制;改为按constBits降序排序 gen buffer 后贪心匹配,引入reusedKill集合防止 kill buffer 被重复使用;每次成功配对后调用reachableMap.unite()传播可达性,支持每个 op 产生多个 VF inplace 配对。 -
简化
IsReuseVFCall判定逻辑:将原先同时检查 gen 可达 StoreOp 且 kill 可达 LoadOp 的&&条件改为!genReachableStore || !killReachableLoad,仅当双侧都可及时才拒绝 inplace 复用。 -
新增回归测试:添加
plan-memory-vf-false-reject.mlir,包含两个测试用例,验证之前被错误拒绝的 VF inplace 配对现在能正确识别为 bufferLife,确保修复有效。


libing-pipeline创建中,请等待……


代码审查
审查总结
逐文件确认:
| 文件 | 审查结论 |
|---|---|
bishengir/include/bishengir/Dialect/HIVM/Transforms/PlanMemory.h |
无问题 — 仅新增 #include、unite/find 方法声明及 parent 成员,接口一致 |
bishengir/lib/Dialect/HIVM/Transforms/PlanMemory.cpp |
发现 1 个 P3 问题(排序 lambda 副作用);其余逻辑(Union-Find、可达性传播、VF 对处理、reusedKill 去重、IsReuseVFCall 语义等价变换)均正确 |
bishengir/test/Dialect/HIVM/plan-memory-vf-false-reject.mlir |
无问题 — 测试用例结构正确,CHECK 指令与输入匹配 |
按严重度统计:
- P0: 0
- P1: 0
- P2: 0
- P3: 1
整体风险评估:低。 此变更的核心逻辑(移除 VF-hopping、以 Union-Find 传播可达性、按 constBits 降序贪心配对、允许每个 op 多个 VF inplace 对)经过仔细推导,未发现正确性或安全性缺陷。唯一报告的问题是排序比较器中 operator[] 的副作用属于防御性改进,在正常数据流下不会触发。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 0 |
⛔ 需要修改


/lgtm


描述 Description
VisitInplaceReuseReachablepreviously hopped to non-conflicting operands within the same VF call viagetInplaceReusableOperands.If any such operand reached a
StoreOp(orLoadOp), its reachability spread to genBuffer/killBuffer in that call, causingIsReuseVFCallto falsely reject valid VF inplace pairs.Fix:
Remove VF-hopping from
VisitInplaceReuseReachable; only trace direct use-def chains (subview, collapse_shape, expand_shape).Add Union-Find to
InplaceReuseReachableMap: reachability now propagates via unite() only after a pair is actually reused, not speculatively.Sort gen descending for optimal greedy pairing.
Allow multiple VF inplace pairs per op.
类型 Category
Checklist