Skip to content

Commit c232240

Browse files
committed
Update with main & Address code review comments
1 parent b705233 commit c232240

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
@@ -208,26 +208,30 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
208208
Expr *lhsExpr = e->getTrueExpr();
209209
Expr *rhsExpr = e->getFalseExpr();
210210

211+
QualType condType = condExpr->getType();
212+
211213
// OpenCL: If the condition is a vector, we can treat this condition like
212214
// the select function.
213-
if ((cgf.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
214-
condExpr->getType()->isExtVectorType()) {
215-
cgf.getCIRGenModule().errorNYI(loc,
216-
"TernaryOp OpenCL VectorType condition");
215+
if ((cgf.getLangOpts().OpenCL && condType->isVectorType()) ||
216+
condType->isExtVectorType()) {
217+
cgf.cgm.errorNYI(loc, "TernaryOp OpenCL VectorType condition");
217218
return {};
218219
}
219220

220-
if (condExpr->getType()->isVectorType() ||
221-
condExpr->getType()->isSveVLSBuiltinType()) {
222-
assert(condExpr->getType()->isVectorType() && "?: op for SVE vector NYI");
221+
if (condType->isVectorType() || condType->isSveVLSBuiltinType()) {
222+
if (!condExpr->getType()->isVectorType()) {
223+
cgf.cgm.errorNYI(loc, "TernaryOp for SVE vector");
224+
return {};
225+
}
226+
223227
mlir::Value condValue = Visit(condExpr);
224228
mlir::Value lhsValue = Visit(lhsExpr);
225229
mlir::Value rhsValue = Visit(rhsExpr);
226230
return builder.create<cir::VecTernaryOp>(loc, condValue, lhsValue,
227231
rhsValue);
228232
}
229233

230-
cgf.getCIRGenModule().errorNYI(loc, "TernaryOp for non vector types");
234+
cgf.cgm.errorNYI(loc, "TernaryOp for non vector types");
231235
return {};
232236
}
233237

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)