Skip to content

Commit 4aa56e8

Browse files
committed
Update with main & Address code review comments
1 parent 030af8e commit 4aa56e8

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
22172217
}];
22182218

22192219
let arguments = (ins
2220-
IntegerVector:$cond,
2220+
CIR_VectorOfIntType:$cond,
22212221
CIR_VectorType:$vec1,
22222222
CIR_VectorType:$vec2
22232223
);

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,26 +200,30 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
200200
Expr *lhsExpr = e->getTrueExpr();
201201
Expr *rhsExpr = e->getFalseExpr();
202202

203+
QualType condType = condExpr->getType();
204+
203205
// OpenCL: If the condition is a vector, we can treat this condition like
204206
// the select function.
205-
if ((cgf.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
206-
condExpr->getType()->isExtVectorType()) {
207-
cgf.getCIRGenModule().errorNYI(loc,
208-
"TernaryOp OpenCL VectorType condition");
207+
if ((cgf.getLangOpts().OpenCL && condType->isVectorType()) ||
208+
condType->isExtVectorType()) {
209+
cgf.cgm.errorNYI(loc, "TernaryOp OpenCL VectorType condition");
209210
return {};
210211
}
211212

212-
if (condExpr->getType()->isVectorType() ||
213-
condExpr->getType()->isSveVLSBuiltinType()) {
214-
assert(condExpr->getType()->isVectorType() && "?: op for SVE vector NYI");
213+
if (condType->isVectorType() || condType->isSveVLSBuiltinType()) {
214+
if (!condExpr->getType()->isVectorType()) {
215+
cgf.cgm.errorNYI(loc, "TernaryOp for SVE vector");
216+
return {};
217+
}
218+
215219
mlir::Value condValue = Visit(condExpr);
216220
mlir::Value lhsValue = Visit(lhsExpr);
217221
mlir::Value rhsValue = Visit(rhsExpr);
218222
return builder.create<cir::VecTernaryOp>(loc, condValue, lhsValue,
219223
rhsValue);
220224
}
221225

222-
cgf.getCIRGenModule().errorNYI(loc, "TernaryOp for non vector types");
226+
cgf.cgm.errorNYI(loc, "TernaryOp for non vector types");
223227
return {};
224228
}
225229

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,7 @@ LogicalResult cir::VecTernaryOp::verify() {
15981598
// other operands. (The automatic verification already checked that all
15991599
// operands are vector types and that the second and third operands are the
16001600
// same type.)
1601-
if (mlir::cast<cir::VectorType>(getCond().getType()).getSize() !=
1602-
getVec1().getType().getSize()) {
1601+
if (getCond().getType().getSize() != getVec1().getType().getSize()) {
16031602
return emitOpError() << ": the number of elements in "
16041603
<< getCond().getType() << " and "
16051604
<< getVec1().getType() << " don't match";

clang/test/CIR/CodeGen/vector-ext.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,18 +1091,3 @@ void foo17() {
10911091
// OGCG: %[[VEC_A:.*]] = alloca <2 x double>, align 16
10921092
// OGCG: %[[TMP:.*]] = load <2 x double>, ptr %[[VEC_A]], align 16
10931093
// OGCG: %[[RES:.*]]= fptoui <2 x double> %[[TMP]] to <2 x i16>
1094-
1095-
void foo20() {
1096-
vi4 a;
1097-
vi4 b;
1098-
vi4 c;
1099-
vi4 r = c ? a : b;
1100-
}
1101-
1102-
// CIR: %[[RES:.*]] = cir.vec.ternary({{.*}}, {{.*}}, {{.*}}) : !cir.vector<4 x !s32i>, !cir.vector<4 x !s32i>
1103-
1104-
// LLVM: %[[VEC_COND:.*]] = icmp ne <4 x i32> {{.*}}, zeroinitializer
1105-
// LLVM: %[[RES:.*]] = select <4 x i1> %[[VEC_COND]], <4 x i32> {{.*}}, <4 x i32> {{.*}}
1106-
1107-
// OGCG: %[[VEC_COND:.*]] = icmp ne <4 x i32> {{.*}}, zeroinitializer
1108-
// OGCG: %[[RES:.*]] = select <4 x i1> %[[VEC_COND]], <4 x i32> {{.*}}, <4 x i32> {{.*}}

0 commit comments

Comments
 (0)