已开启
[MLIR][Transform] transform.legalize 的 CleanupExtractSlice 模式忽略 transfer_read 的 permutation_map,把切片偏移加到错误的 memref 维度上 #132
cactusBalll创建于  6 天前
cactusBalll
6 天前 创建

【缺陷描述】:请补充详细的缺陷问题现象描述

对合法 MLIR——vector.transfer_read 带非恒等 permutation_map(例如读矩阵的某一列)后接 vector.extract_strided_slice——transform.legalize 的 CleanupExtractSlice 模式把切出的新 read 的地址算错:

  • 输入:permutation_map = affine_map<(d0, d1) -> (d0)>(结果维度对应 memref 维度 0),read 索引 [i, j],extract offsets = [4]
  • 模式生成的新 read 索引为 [i, j+4]——把偏移加到了最后一个 memref 维度上
  • 正确地址(结果元素 [4,8) 对应的 memref 位置)应为 [i+4, j]

生成的程序读取完全不同的数据,无任何诊断。2-D 转置映射 permutation_map = (d0, d1) -> (d1, d0) 同样错误(最后结果维 d0 对应 memref 维度 0,模式却调整 d1)。

一、缺陷信息

  • 缺陷组件:MLIR Transform dialect(TransformOps.cpp,CleanupExtractSlice::matchAndRewrite,当前树 3079-3132 行)
  • 根因:模式假定 read 的最后一个结果维度对应最后一个 memref 索引,恒做
    auto ofs = rewriter.create<arith::ConstantIndexOp>(loc, offsets[offsets.size() - 1]);
    auto addidx = rewriter.create<arith::AddIOp>(loc, indices[indices.size() - 1], ofs);  // 恒为最后一个 memref 索引
    
    从不检查 readOp.getPermutationMap() 来确定被切片的(最后)向量维度实际由哪个 memref 维度支撑;新建 read 时 permutation_map 原样复制但寻址语义已被破坏。该假定仅对恒等映射成立

缺陷关联提交(两次修复均重塑同一 pattern,错误始终存在):

  • 30228109586cf5eae5d6898d3ffae9e4a71ccdae "[mlir][transform] Fix Use-After-Free error in transform.legalize"
  • d18ff5dbbd3d22016b557afac46274fb44649896 "[mlir][transform] Fix dominance violation in CleanupExtractSlice"
  • pattern 引入:0d042c157b7a65ee48ab2920b67f95113f9347da "legalize"

【缺陷所属的os版本】

Ubuntu 22.04.3 LTS,缺陷位于编译器/MLIR 工具链本身,与操作系统版本无关。

【内核版本】

6.6.87.2-microsoft-standard-WSL2(uname -r)。缺陷与内核版本无关。

【缺陷所属软件及版本号】

LLVM 20.1.8

【环境信息】

编译选项:
CMAKE_BUILD_TYPE=RelWithDebInfo,LLVM_ENABLE_ASSERTIONS=ON,LLVM_ENABLE_PROJECTS="clang;mlir",LLVM_TARGETS_TO_BUILD="X86;AArch64"

COMMIT ID:35f464110c04e89bd0cab0e3fee4a70ec6ec2eb9

【问题复现步骤】

func.func @perm_map_d0(%m: memref<8x8xf32>, %i: index, %j: index) -> vector<4xf32> {
  %pad = arith.constant 0.0 : f32
  %v = vector.transfer_read %m[%i, %j], %pad {in_bounds = [true], permutation_map = affine_map<(d0, d1) -> (d0)>} : memref<8x8xf32>, vector<8xf32>
  %e = vector.extract_strided_slice %v {offsets = [4], sizes = [4], strides = [1]} : vector<8xf32> to vector<4xf32>
  return %e : vector<4xf32>
}

module attributes {transform.with_named_sequence} {
  transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
    transform.legalize {hardware_vector_length = 256 : i64}
    transform.yield
  }
}

执行mlir-opt test.mlir --transform-interpreter,检查输出中新建 vector.transfer_read 的 indices 与 permutation_map 的组合语义

【实际结果】

【期望结果】

【其他相关附件信息】

【缺陷详情及分析指导参考链接】

likedislike
openeuler-ci-botopeneuler-ci-bot成员
6 天前 将 alexanderbill、li-yancheng、cf-zhao、eastb233、wangqiang95、kuenking111_admin、SegFault、wd-gitcode、chenzheng1030、gcw_LWQavIsb 设为负责人
openeuler-ci-botopeneuler-ci-bot成员
6 天前 添加了label:sig/Compiler
openeuler-ci-bot
openeuler-ci-bot成员
6 天前 评论:

Welcome To openEuler Community

Hey @gcw_LWQavIsb , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: Compiler ,
and any of the maintainers: @SegFault, @alexanderbill, @cf-zhao, @chenzheng1030, @eastb233, @kuenking111_admin, @li-yancheng, @wangqiang95, @wd-gitcode ,
and any of the committers: @liyunfei33, @zhongyunde .

likedislike