Skip to content

Commit 14e8806

Browse files
committed
[CIR][CIRGen] Fix compound assignment for vector types
1 parent 43094d7 commit 14e8806

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,13 @@ RValue CIRGenFunction::buildLoadOfLValue(LValue LV, SourceLocation Loc) {
646646

647647
if (LV.isSimple())
648648
return RValue::get(buildLoadOfScalar(LV, Loc));
649+
650+
if (LV.isVectorElt()) {
651+
auto load = builder.createLoad(getLoc(Loc), LV.getVectorAddress());
652+
return RValue::get(builder.create<mlir::cir::VecExtractOp>(
653+
getLoc(Loc), load, LV.getVectorIdx()));
654+
}
655+
649656
llvm_unreachable("NYI");
650657
}
651658

clang/test/CIR/CodeGen/vectype.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ void vector_int_test(int x) {
4242
// CHECK: %[[#UPDATEDVI:]] = cir.vec.insert %{{[0-9]+}}, %[[#LOADEDVI]][%{{[0-9]+}} : !s32i] : !cir.vector<!s32i x 4>
4343
// CHECK: cir.store %[[#UPDATEDVI]], %[[#STORAGEVI]] : !cir.vector<!s32i x 4>, !cir.ptr<!cir.vector<!s32i x 4>>
4444

45+
// Compound assignment
46+
a[x] += a[0];
47+
// CHECK: %[[#RHSCA:]] = cir.vec.extract %{{[0-9]+}}[%{{[0-9]+}} : !s32i] : !cir.vector<!s32i x 4>
48+
// CHECK: %[[#LHSCA:]] = cir.vec.extract %{{[0-9]+}}[%{{[0-9]+}} : !s32i] : !cir.vector<!s32i x 4>
49+
// CHECK: %[[#SUMCA:]] = cir.binop(add, %[[#LHSCA]], %[[#RHSCA]]) : !s32i
50+
// CHECK: cir.vec.insert %[[#SUMCA]], %{{[0-9]+}}[%{{[0-9]+}} : !s32i] : !cir.vector<!s32i x 4>
51+
4552
// Binary arithmetic operations
4653
vi4 d = a + b;
4754
// CHECK: %{{[0-9]+}} = cir.binop(add, %{{[0-9]+}}, %{{[0-9]+}}) : !cir.vector<!s32i x 4>

0 commit comments

Comments
 (0)