[clang] [CIR] Preserve volatile on vector element loads and stores (PR #249304)
Arseniy Obolenskiy via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 5 14:44:26 PST 2026
https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/249304
Indexed accesses like (*p)[i] dropped volatile
>From ece4dfaf2f4b8ed4807e8936096b71059c2ee593 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Sat, 5 Dec 2026 23:39:11 +0100
Subject: [PATCH] [CIR] Preserve volatile on vector element loads and stores
Indexed accesses like (*p)[i] dropped volatile
---
clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 7 ++++---
clang/test/CIR/CodeGenOpenCL/vector.cl | 14 ++++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
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
More information about the cfe-commits
mailing list