[clang] [CIR] Preserve volatile on vector element loads and stores (PR #249304)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 5 14:45:02 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
Indexed accesses like (*p)[i] dropped volatile
---
Full diff: https://github.com/llvm/llvm-project/pull/249304.diff
2 Files Affected:
- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+4-3)
- (modified) clang/test/CIR/CodeGenOpenCL/vector.cl (+14)
``````````diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index d17c324ed1dd74..6fe6bcb21d577b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -471,10 +471,11 @@ void CIRGenFunction::emitStoreThroughLValue(RValue src, LValue dst,
// Read/modify/write the vector, inserting the new element
const mlir::Location loc = dst.getVectorPointer().getLoc();
const mlir::Value vector =
- builder.createLoad(loc, dst.getVectorAddress());
+ builder.createLoad(loc, dst.getVectorAddress(), dst.isVolatile());
const mlir::Value newVector = builder.createInsertElement(
loc, vector, src.getValue(), dst.getVectorIdx());
- builder.createStore(loc, newVector, dst.getVectorAddress());
+ builder.createStore(loc, newVector, dst.getVectorAddress(),
+ dst.isVolatileQualified());
return;
}
@@ -938,7 +939,7 @@ RValue CIRGenFunction::emitLoadOfLValue(LValue lv, SourceLocation loc) {
if (lv.isVectorElt()) {
const mlir::Value load =
- builder.createLoad(getLoc(loc), lv.getVectorAddress());
+ builder.createLoad(getLoc(loc), lv.getVectorAddress(), lv.isVolatile());
return RValue::get(
builder.createExtractElement(getLoc(loc), load, lv.getVectorIdx()));
}
diff --git a/clang/test/CIR/CodeGenOpenCL/vector.cl b/clang/test/CIR/CodeGenOpenCL/vector.cl
index 7e65629bce30e9..687247c063edd1 100644
--- a/clang/test/CIR/CodeGenOpenCL/vector.cl
+++ b/clang/test/CIR/CodeGenOpenCL/vector.cl
@@ -285,3 +285,17 @@ void vec_volatile_swizzle_unused(volatile int4 *p) {
// LLVM: load volatile <4 x i32>, ptr %{{.*}}, align 16
// LLVM: load volatile <4 x i32>, ptr %{{.*}}, align 16
// LLVM: ret void
+
+void vec_volatile_subscript_compound(volatile int4 *p, int i, int v) {
+ (*p)[i] += v;
+}
+
+// CIR-LABEL: cir.func {{.*}} @vec_volatile_subscript_compound
+// CIR: cir.load volatile {{.*}} : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
+// CIR: cir.load volatile {{.*}} : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
+// CIR: cir.store volatile {{.*}} : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
+
+// LLVM-LABEL: @vec_volatile_subscript_compound
+// LLVM: load volatile <4 x i32>, ptr %{{.*}}, align 16
+// LLVM: load volatile <4 x i32>, ptr %{{.*}}, align 16
+// LLVM: store volatile <4 x i32> %{{.*}}, ptr %{{.*}}, align 16
``````````
</details>
https://github.com/llvm/llvm-project/pull/249304
More information about the cfe-commits
mailing list