已开启
[MLIR][LLVM] --llvm-promote-i1-to-i8 提升 load 时静默丢弃 volatile 与 nontemporal 属性 #130
cactusBalll创建于  4 天前
cactusBalll
4 天前 创建

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

mlir-opt --llvm-promote-i1-to-i8

%0 = llvm.load volatile %p : !llvm.ptr -> vector<4xi1>

改写为

%0 = llvm.load %p : !llvm.ptr -> vector<4xi8>

volatile 关键字被静默丢弃nontemporal unit 属性同样丢失。alignment 是唯一被保留的属性。store 路径仅交换操作数、属性不受影响,仅 load 受影响。

语义影响:volatile load 不允许优化器删除、合并或移动;提升后变为普通 load,可能被作为死代码删除(trunc 后若结果未用)、被合并或外提出循环。对 MMIO、与外设/其他线程有副作用的访问(i1 向量常来自 predicate/mask 通道的设备内存)构成静默错码风险。scalable 向量变体提交(342f2196e)共享同一代码路径与缺陷。

一、缺陷信息

【缺陷所属的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

【问题复现步骤】

// BUG: --llvm-promote-i1-to-i8 silently drops `volatile` and `nontemporal`
// from promoted vector<i1> loads (alignment IS preserved).
module {
  llvm.func @load_volatile(%p : !llvm.ptr) -> vector<4xi1> {
    %0 = llvm.load volatile %p : !llvm.ptr -> vector<4xi1>
    llvm.return %0 : vector<4xi1>
  }
  llvm.func @load_nontemporal(%p : !llvm.ptr) -> vector<4xi1> {
    %0 = llvm.load %p {nontemporal} : !llvm.ptr -> vector<4xi1>
    llvm.return %0 : vector<4xi1>
  }
  // Controls: alignment preserved; store volatile preserved.
  llvm.func @load_aligned(%p : !llvm.ptr) -> vector<4xi1> {
    %0 = llvm.load %p {alignment = 4 : i64} : !llvm.ptr -> vector<4xi1>
    llvm.return %0 : vector<4xi1>
  }
  llvm.func @store_volatile(%v : vector<4xi1>, %p : !llvm.ptr) {
    llvm.store volatile %v, %p : vector<4xi1>, !llvm.ptr
    llvm.return
  }
}

执行mlir-opt repro.mlir --llvm-promote-i1-to-i8,观察输出中的 llvm.load(volatile 关键字消失)

【实际结果】

【期望结果】

【其他相关附件信息】

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

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

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