[clang] [CIR] Implement cir.cmp3way Operation (PR #186294)
Zaky Hermawan via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 12 19:50:04 PDT 2026
================
@@ -326,7 +324,47 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
Visit(e->getRHS());
}
void VisitBinCmp(const BinaryOperator *e) {
- cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitBinCmp");
+ const ComparisonCategoryInfo &CompCategoryInfo =
+ cgf.getContext().CompCategories.getInfoForType(e->getType());
+
+ QualType ArgTy = e->getLHS()->getType();
+ if (ArgTy->isIntegralOrEnumerationType() || ArgTy->isRealFloatingType() ||
+ ArgTy->isNullPtrType() || ArgTy->isPointerType() ||
+ ArgTy->isMemberPointerType()) {
+ mlir::Value lhs = cgf.emitScalarExpr(e->getLHS());
+ mlir::Value rhs = cgf.emitScalarExpr(e->getRHS());
+
+ mlir::Attribute info;
+ if (CompCategoryInfo.isStrong()) {
+ info = cir::CmpThreeWayStrongInfoAttr::get(
+ cgf.getBuilder().getContext(),
+ CompCategoryInfo.getLess()->getIntValue().getSExtValue(),
+ CompCategoryInfo.getEqualOrEquiv()->getIntValue().getSExtValue(),
+ CompCategoryInfo.getGreater()->getIntValue().getSExtValue());
+ } else {
+ info = cir::CmpThreeWayPartialInfoAttr::get(
+ cgf.getBuilder().getContext(),
+ CompCategoryInfo.getLess()->getIntValue().getSExtValue(),
+ CompCategoryInfo.getEqualOrEquiv()->getIntValue().getSExtValue(),
+ CompCategoryInfo.getGreater()->getIntValue().getSExtValue(),
+ CompCategoryInfo.getUnordered()->getIntValue().getSExtValue());
+ }
+ mlir::Type resultTy = cgf.convertType(cgf.getContext().IntTy);
+ mlir::Value result = cgf.getBuilder().createThreeWayComparison(
+ cgf.getLoc(e->getSourceRange()), resultTy, lhs, rhs, info);
+
+ ensureDest(cgf.getLoc(e->getSourceRange()), e->getType());
+ LValue destLValue = cgf.makeAddrLValue(dest.getAddress(), e->getType());
+
+ const FieldDecl *field = *CompCategoryInfo.Record->field_begin();
+ LValue fieldLValue = cgf.emitLValueForFieldInitialization(
+ destLValue, field, field->getName());
+ cgf.emitStoreThroughLValue(RValue::get(result), fieldLValue, true);
+ } else {
+ cgf.cgm.errorNYI(e->getSourceRange(),
+ "AggExprEmitter: unsupported operand type");
----------------
ZakyHermawan wrote:
Is it possible to provide more information ?
For example, what operand is this.
https://github.com/llvm/llvm-project/pull/186294
More information about the cfe-commits
mailing list