llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clangir Author: Arseniy Obolenskiy (aobolensk) <details> <summary>Changes</summary> Swizzle reads of volatile vectors emitted non-volatile loads, so CIR deleted unused reads such as `p->x;` Swizzle store in contrast already keeps the flag --- Full diff: https://github.com/llvm/llvm-project/pull/244410.diff 2 Files Affected: - (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+2-1) - (modified) clang/test/CIR/CodeGenOpenCL/vector.cl (+41) ``````````diff diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 8a885755143092..14703360c608d2 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -875,7 +875,8 @@ int64_t CIRGenFunction::getAccessedFieldNo(unsigned int idx, // appropriate shufflevector. RValue CIRGenFunction::emitLoadOfExtVectorElementLValue(LValue lv) { mlir::Location loc = lv.getExtVectorPointer().getLoc(); - mlir::Value vec = builder.createLoad(loc, lv.getExtVectorAddress()); + mlir::Value vec = + builder.createLoad(loc, lv.getExtVectorAddress(), lv.isVolatile()); // HLSL allows treating scalars as one-element vectors. Converting the scalar // IR value to a vector here allows the rest of codegen to behave as normal. diff --git a/clang/test/CIR/CodeGenOpenCL/vector.cl b/clang/test/CIR/CodeGenOpenCL/vector.cl index dfb493906d471f..78d130921550b3 100644 --- a/clang/test/CIR/CodeGenOpenCL/vector.cl +++ b/clang/test/CIR/CodeGenOpenCL/vector.cl @@ -244,3 +244,44 @@ int4 vec_init_narrow_swizzle(int2 b) { // LLVM-LABEL: @vec_init_narrow_swizzle // LLVM: %[[RESULT:.*]] = shufflevector <2 x i32> %{{.*}}, <2 x i32> poison, <4 x i32> <i32 1, i32 0, i32 0, i32 1> // LLVM: ret <4 x i32> %[[RESULT]] + +int vec_volatile_swizzle_scalar(volatile int4 *p) { + return p->x; +} + +// CIR-LABEL: cir.func {{.*}} @vec_volatile_swizzle_scalar +// CIR: %[[V:.*]] = cir.load volatile {{.*}} : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i> +// CIR: cir.vec.extract %[[V]][%{{.*}} : !s64i] : !cir.vector<4 x !s32i> + +// LLVM-LABEL: @vec_volatile_swizzle_scalar +// LLVM: %[[V:.*]] = load volatile <4 x i32>, ptr %{{.*}}, align 16 +// LLVM: %[[X:.*]] = extractelement <4 x i32> %[[V]], i64 0 +// LLVM: ret i32 %[[X]] + +int2 vec_volatile_swizzle_multi(volatile int4 *p) { + return p->xy; +} + +// CIR-LABEL: cir.func {{.*}} @vec_volatile_swizzle_multi +// CIR: %[[V:.*]] = cir.load volatile {{.*}} : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i> +// CIR: cir.vec.shuffle(%[[V]], %{{.*}} : !cir.vector<4 x !s32i>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i] : !cir.vector<2 x !s32i> + +// LLVM-LABEL: @vec_volatile_swizzle_multi +// LLVM: %[[V:.*]] = load volatile <4 x i32>, ptr %{{.*}}, align 16 +// LLVM: %[[XY:.*]] = shufflevector <4 x i32> %[[V]], <4 x i32> poison, <2 x i32> <i32 0, i32 1> +// LLVM: ret <2 x i32> %[[XY]] + +void vec_volatile_swizzle_unused(volatile int4 *p) { + p->x; + p->xy; +} + +// CIR-LABEL: cir.func {{.*}} @vec_volatile_swizzle_unused +// 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.return + +// LLVM-LABEL: @vec_volatile_swizzle_unused +// LLVM: load volatile <4 x i32>, ptr %{{.*}}, align 16 +// LLVM: load volatile <4 x i32>, ptr %{{.*}}, align 16 +// LLVM: ret void `````````` </details> https://github.com/llvm/llvm-project/pull/244410 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
