-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CIR] Upstream support for logical not operations #133966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -488,6 +488,8 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { | |
return emitUnaryOp(e, cir::UnaryOpKind::Not, op); | ||
} | ||
|
||
mlir::Value VisitUnaryLNot(const UnaryOperator *e); | ||
|
||
/// Emit a conversion from the specified type to the specified destination | ||
/// type, both of which are CIR scalar types. | ||
/// TODO: do we need ScalarConversionOpts here? Should be done in another | ||
|
@@ -1315,7 +1317,7 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) { | |
"fixed point casts"); | ||
return {}; | ||
} | ||
cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(), "fp options"); | ||
assert(!cir::MissingFeatures::cgFPOptionsRAII()); | ||
return emitScalarConversion(Visit(subExpr), subExpr->getType(), destTy, | ||
ce->getExprLoc()); | ||
} | ||
|
@@ -1353,6 +1355,33 @@ mlir::Value CIRGenFunction::emitScalarConversion(mlir::Value src, | |
.emitScalarConversion(src, srcTy, dstTy, loc); | ||
} | ||
|
||
mlir::Value ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *e) { | ||
// Perform vector logical not on comparison with zero vector. | ||
if (e->getType()->isVectorType() && | ||
e->getType()->castAs<VectorType>()->getVectorKind() == | ||
VectorKind::Generic) { | ||
assert(!cir::MissingFeatures::vectorType()); | ||
cgf.cgm.errorNYI(e->getSourceRange(), "vector logical not"); | ||
return {}; | ||
} | ||
|
||
// Compare operand to zero. | ||
mlir::Value boolVal = cgf.evaluateExprAsBool(e->getSubExpr()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be necessary AFAIK. Clang should have already converted the expression via casts to bool. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered about that. This may be something we just blindly brought over from the classic codegen, which does the same thing. I'll try changing it there and run the regression tests to see if anything fails. If not, I'll remove it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I went to test the change, it became obvious why this is here, and I remembered that we had this same discussion a couple of weeks ago with the for-loop upstreaming. We have a boolean expression, but we need to emit a value. The AST will have an implicit cast to bool here, but I tried replacing this with emitScalarExpr in the classic codegen, and it does cause problems when the |
||
|
||
// Invert value. | ||
boolVal = builder.createNot(boolVal); | ||
|
||
// ZExt result to the expr type. | ||
mlir::Type dstTy = cgf.convertType(e->getType()); | ||
if (mlir::isa<cir::IntType>(dstTy)) | ||
return builder.createBoolToInt(boolVal, dstTy); | ||
if (mlir::isa<cir::BoolType>(dstTy)) | ||
return boolVal; | ||
|
||
cgf.cgm.errorNYI("destination type for logical-not unary operator is NYI"); | ||
return {}; | ||
} | ||
|
||
/// Return the size or alignment of the type of argument of the sizeof | ||
/// expression as an integer. | ||
mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr( | ||
|
Uh oh!
There was an error while loading. Please reload this page.