Skip to content

Commit 98e3de4

Browse files
AmrDeveloperlanza
authored andcommitted
[CIR] Backport logical not for VectorType (#1979)
Backporting support for logical not for VectorType from the upstream
1 parent 77ddcbc commit 98e3de4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,13 @@ mlir::Value ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *E) {
20652065
if (E->getType()->isVectorType() &&
20662066
E->getType()->castAs<VectorType>()->getVectorKind() ==
20672067
VectorKind::Generic) {
2068-
llvm_unreachable("NYI");
2068+
mlir::Value oper = Visit(E->getSubExpr());
2069+
mlir::Location loc = CGF.getLoc(E->getExprLoc());
2070+
auto operVecTy = mlir::cast<cir::VectorType>(oper.getType());
2071+
auto exprVecTy = mlir::cast<cir::VectorType>(CGF.convertType(E->getType()));
2072+
mlir::Value zeroVec = Builder.getNullValue(operVecTy, loc);
2073+
return cir::VecCmpOp::create(Builder, loc, exprVecTy, cir::CmpOpKind::eq,
2074+
oper, zeroVec);
20692075
}
20702076

20712077
// Compare operand to zero.

clang/test/CIR/CodeGen/vectype.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ typedef unsigned int uvi4 __attribute__((vector_size(16)));
55
typedef double vd2 __attribute__((vector_size(16)));
66
typedef long long vll2 __attribute__((vector_size(16)));
77
typedef unsigned short vus2 __attribute__((vector_size(4)));
8+
typedef float vf4 __attribute__((vector_size(16)));
89

910
vi4 vec_a;
1011
// CHECK: cir.global external @[[VEC_A:.*]] = #cir.zero : !cir.vector<!s32i x 4>
@@ -221,3 +222,27 @@ void vector_integers_shifts_test() {
221222
uvi4 shr = b >> a;
222223
// CHECK: %{{[0-9]+}} = cir.shift(right, %{{[0-9]+}} : !cir.vector<!u32i x 4>, %{{[0-9]+}} : !cir.vector<!s32i x 4>) -> !cir.vector<!u32i x 4>
223224
}
225+
226+
void logical_not() {
227+
vi4 a;
228+
vi4 b = !a;
229+
}
230+
231+
// CHECK: %[[A_ADDR:.*]] = cir.alloca !cir.vector<!s32i x 4>, !cir.ptr<!cir.vector<!s32i x 4>>, ["a"]
232+
// CHECK: %[[B_ADDR:.*]] = cir.alloca !cir.vector<!s32i x 4>, !cir.ptr<!cir.vector<!s32i x 4>>, ["b", init]
233+
// CHECK: %[[TMP_A:.*]] = cir.load{{.*}}) %[[A_ADDR]] : !cir.ptr<!cir.vector<!s32i x 4>>, !cir.vector<!s32i x 4>
234+
// CHECK: %[[CONST_V0:.*]] = cir.const #cir.zero : !cir.vector<!s32i x 4>
235+
// CHECK: %[[RESULT:.*]] = cir.vec.cmp(eq, %[[TMP_A]], %[[CONST_V0]]) : !cir.vector<!s32i x 4>, !cir.vector<!s32i x 4>
236+
// CHECK: cir.store{{.*}} %[[RESULT]], %[[B_ADDR]] : !cir.vector<!s32i x 4>, !cir.ptr<!cir.vector<!s32i x 4>>
237+
238+
void logical_not_float() {
239+
vf4 a;
240+
vi4 b = !a;
241+
}
242+
243+
// CHECK: %[[A_ADDR:.*]] = cir.alloca !cir.vector<!cir.float x 4>, !cir.ptr<!cir.vector<!cir.float x 4>>, ["a"]
244+
// CHECK: %[[B_ADDR:.*]] = cir.alloca !cir.vector<!s32i x 4>, !cir.ptr<!cir.vector<!s32i x 4>>, ["b", init]
245+
// CHECK: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.vector<!cir.float x 4>>, !cir.vector<!cir.float x 4>
246+
// CHECK: %[[CONST_V0:.*]] = cir.const #cir.zero : !cir.vector<!cir.float x 4>
247+
// CHECK: %[[RESULT:.*]] = cir.vec.cmp(eq, %[[TMP_A]], %[[CONST_V0]]) : !cir.vector<!cir.float x 4>, !cir.vector<!s32i x 4>
248+
// CHECK: cir.store{{.*}} %[[RESULT]], %[[B_ADDR]] : !cir.vector<!s32i x 4>, !cir.ptr<!cir.vector<!s32i x 4>>

0 commit comments

Comments
 (0)