Skip to content

Commit 6a2a7fa

Browse files
committed
Add test case for vector of floats
1 parent c5a0b25 commit 6a2a7fa

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,9 +2089,11 @@ mlir::Value ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *e) {
20892089
VectorKind::Generic) {
20902090
mlir::Value oper = Visit(e->getSubExpr());
20912091
mlir::Location loc = cgf.getLoc(e->getExprLoc());
2092-
mlir::Value zero = builder.getNullValue(oper.getType(), loc);
2093-
return cir::VecCmpOp::create(builder, loc, oper.getType(),
2094-
cir::CmpOpKind::eq, oper, zero);
2092+
auto operVecTy = mlir::cast<cir::VectorType>(oper.getType());
2093+
auto exprVecTy = mlir::cast<cir::VectorType>(cgf.convertType(e->getType()));
2094+
mlir::Value zeroVec = builder.getNullValue(operVecTy, loc);
2095+
return cir::VecCmpOp::create(builder, loc, exprVecTy, cir::CmpOpKind::eq,
2096+
oper, zeroVec);
20952097
}
20962098

20972099
// Compare operand to zero.
@@ -2362,4 +2364,4 @@ mlir::Value CIRGenFunction::emitScalarPrePostIncDec(const UnaryOperator *e,
23622364
bool isPre) {
23632365
return ScalarExprEmitter(*this, builder)
23642366
.emitScalarPrePostIncDec(e, lv, kind, isPre);
2365-
}
2367+
}

clang/test/CIR/CodeGen/vector.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,3 +1364,29 @@ void logical_not() {
13641364
// OGCG: %[[RESULT:.*]] = icmp eq <4 x i32> %[[TMP_A]], zeroinitializer
13651365
// OGCG: %[[RESULT_VI4:.*]] = sext <4 x i1> %[[RESULT]] to <4 x i32>
13661366
// OGCG: store <4 x i32> %[[RESULT_VI4]], ptr %[[B_ADDR]], align 16
1367+
1368+
void logical_not_float() {
1369+
vf4 a;
1370+
vi4 b = !a;
1371+
}
1372+
1373+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.vector<4 x !cir.float>, !cir.ptr<!cir.vector<4 x !cir.float>>, ["a"]
1374+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["b", init]
1375+
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.vector<4 x !cir.float>>, !cir.vector<4 x !cir.float>
1376+
// CIR: %[[CONST_V0:.*]] = cir.const #cir.zero : !cir.vector<4 x !cir.float>
1377+
// CIR: %[[RESULT:.*]] = cir.vec.cmp(eq, %[[TMP_A]], %[[CONST_V0]]) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i>
1378+
// CIR: cir.store{{.*}} %[[RESULT]], %[[B_ADDR]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
1379+
1380+
// LLVM: %[[A_ADDR:.*]] = alloca <4 x float>, i64 1, align 16
1381+
// LLVM: %[[B_ADDR:.*]] = alloca <4 x i32>, i64 1, align 16
1382+
// LLVM: %[[TMP_A:.*]] = load <4 x float>, ptr %[[A_ADDR]], align 16
1383+
// LLVM: %[[RESULT:.*]] = fcmp oeq <4 x float> %[[TMP_A]], zeroinitializer
1384+
// LLVM: %[[RESULT_VI4:.*]] = sext <4 x i1> %[[RESULT]] to <4 x i32>
1385+
// LLVM: store <4 x i32> %[[RESULT_VI4]], ptr %[[B_ADDR]], align 16
1386+
1387+
// OGCG: %[[A_ADDR:.*]] = alloca <4 x float>, align 16
1388+
// OGCG: %[[B_ADDR:.*]] = alloca <4 x i32>, align 16
1389+
// OGCG: %[[TMP_A:.*]] = load <4 x float>, ptr %[[A_ADDR]], align 16
1390+
// OGCG: %[[RESULT:.*]] = fcmp oeq <4 x float> %[[TMP_A]], zeroinitializer
1391+
// OGCG: %[[RESULT_VI4:.*]] = sext <4 x i1> %[[RESULT]] to <4 x i32>
1392+
// OGCG: store <4 x i32> %[[RESULT_VI4]], ptr %[[B_ADDR]], align 16

0 commit comments

Comments
 (0)