Skip to content

Commit dad7c84

Browse files
authored
[CIR][CIRGen] Fix compound assignment for vector types (#610)
There is [a code path](https://github.com/llvm/clangir/blob/3da10fafac66ff125fb59c602e41ad4b4f5cb382/clang/lib/CodeGen/CGExpr.cpp#L2190) missing the counterpart in CIRGen of vector types. When using compound assignments like `a[0] += a[1]`, this code path is activated and end up with NYI.
1 parent ff44cfb commit dad7c84

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-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

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ 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: %[[#LOADCA1:]] = cir.load %{{[0-9]+}} : !cir.ptr<!cir.vector<!s32i x 4>>, !cir.vector<!s32i x 4>
48+
// CHECK: %[[#RHSCA:]] = cir.vec.extract %[[#LOADCA1]][%{{[0-9]+}} : !s32i] : !cir.vector<!s32i x 4>
49+
// CHECK: %[[#LOADCAIDX2:]] = cir.load %{{[0-9]+}} : !cir.ptr<!s32i>, !s32i
50+
// CHECK: %[[#LOADCAVEC3:]] = cir.load %{{[0-9]+}} : !cir.ptr<!cir.vector<!s32i x 4>>, !cir.vector<!s32i x 4>
51+
// CHECK: %[[#LHSCA:]] = cir.vec.extract %[[#LOADCAVEC3]][%[[#LOADCAIDX2]] : !s32i] : !cir.vector<!s32i x 4>
52+
// CHECK: %[[#SUMCA:]] = cir.binop(add, %[[#LHSCA]], %[[#RHSCA]]) : !s32i
53+
// CHECK: %[[#LOADCAVEC4:]] = cir.load %{{[0-9]+}} : !cir.ptr<!cir.vector<!s32i x 4>>, !cir.vector<!s32i x 4>
54+
// CHECK: %[[#RESULTCAVEC:]] = cir.vec.insert %[[#SUMCA]], %[[#LOADCAVEC4]][%[[#LOADCAIDX2]] : !s32i] : !cir.vector<!s32i x 4>
55+
// CHECK: cir.store %[[#RESULTCAVEC]], %{{[0-9]+}} : !cir.vector<!s32i x 4>, !cir.ptr<!cir.vector<!s32i x 4>>
56+
4557
// Binary arithmetic operations
4658
vi4 d = a + b;
4759
// CHECK: %{{[0-9]+}} = cir.binop(add, %{{[0-9]+}}, %{{[0-9]+}}) : !cir.vector<!s32i x 4>

clang/test/CIR/Lowering/vectype.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ void vector_int_test(int x) {
7474
// CHECK: %[[#T64:]] = llvm.insertelement %[[#T61]], %[[#T63]][%[[#T62]] : i32] : vector<4xi32>
7575
// CHECK: llvm.store %[[#T64]], %[[#T3]] : vector<4xi32>, !llvm.ptr
7676

77+
// Compound assignment
78+
a[x] += a[0];
79+
// CHECK: %[[#LOADCA1:]] = llvm.load %{{[0-9]+}} : !llvm.ptr -> vector<4xi32>
80+
// CHECK: %[[#RHSCA:]] = llvm.extractelement %[[#LOADCA1:]][%{{[0-9]+}} : i32] : vector<4xi32>
81+
// CHECK: %[[#LOADCAIDX2:]] = llvm.load %{{[0-9]+}} : !llvm.ptr -> i32
82+
// CHECK: %[[#LOADCAVEC3:]] = llvm.load %{{[0-9]+}} : !llvm.ptr -> vector<4xi32>
83+
// CHECK: %[[#LHSCA:]] = llvm.extractelement %[[#LOADCAVEC3:]][%[[#LOADCAIDX2:]] : i32] : vector<4xi32>
84+
// CHECK: %[[#SUMCA:]] = llvm.add %[[#LHSCA:]], %[[#RHSCA:]] : i32
85+
// CHECK: %[[#LOADCAVEC4:]] = llvm.load %{{[0-9]+}} : !llvm.ptr -> vector<4xi32>
86+
// CHECK: %[[#RESULTCAVEC:]] = llvm.insertelement %[[#SUMCA:]], %[[#LOADCAVEC4:]][%[[#LOADCAIDX2:]] : i32] : vector<4xi32>
87+
// CHECK: llvm.store %[[#RESULTCAVEC:]], %{{[0-9]+}} : vector<4xi32>, !llvm.ptr
88+
7789
// Binary arithmetic operators.
7890
vi4 d = a + b;
7991
// CHECK: %[[#T65:]] = llvm.load %[[#T3]] : !llvm.ptr -> vector<4xi32>

0 commit comments

Comments
 (0)