Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,38 +617,26 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
QualType promotionTy = PromotionType.isNull()
? getPromotionType(E->getSubExpr()->getType())
: PromotionType;
auto result = VisitPlus(E, promotionTy);
auto result = emitUnaryPlusOrMinus(E, cir::UnaryOpKind::Plus, promotionTy);
if (result && !promotionTy.isNull())
return emitUnPromotedValue(result, E->getType());
return result;
}

mlir::Value VisitPlus(const UnaryOperator *E,
QualType PromotionType = QualType()) {
// This differs from gcc, though, most likely due to a bug in gcc.
TestAndClearIgnoreResultAssign();

mlir::Value operand;
if (!PromotionType.isNull())
operand = CGF.emitPromotedScalarExpr(E->getSubExpr(), PromotionType);
else
operand = Visit(E->getSubExpr());

return emitUnaryOp(E, cir::UnaryOpKind::Plus, operand);
}

mlir::Value VisitUnaryMinus(const UnaryOperator *E,
QualType PromotionType = QualType()) {
QualType promotionTy = PromotionType.isNull()
? getPromotionType(E->getSubExpr()->getType())
: PromotionType;
auto result = VisitMinus(E, promotionTy);
auto result = emitUnaryPlusOrMinus(E, cir::UnaryOpKind::Minus, promotionTy);
if (result && !promotionTy.isNull())
return emitUnPromotedValue(result, E->getType());
return result;
}

mlir::Value VisitMinus(const UnaryOperator *E, QualType PromotionType) {
mlir::Value emitUnaryPlusOrMinus(const UnaryOperator *E,
cir::UnaryOpKind kind,
QualType PromotionType) {
TestAndClearIgnoreResultAssign();

mlir::Value operand;
Expand All @@ -657,10 +645,12 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
else
operand = Visit(E->getSubExpr());

bool nsw =
kind == cir::UnaryOpKind::Minus && E->getType()->isSignedIntegerType();

// NOTE: LLVM codegen will lower this directly to either a FNeg
// or a Sub instruction. In CIR this will be handled later in LowerToLLVM.
return emitUnaryOp(E, cir::UnaryOpKind::Minus, operand,
/*nsw=*/E->getType()->isSignedIntegerType());
return emitUnaryOp(E, kind, operand, nsw);
}

mlir::Value VisitUnaryNot(const UnaryOperator *E) {
Expand Down Expand Up @@ -2334,9 +2324,9 @@ mlir::Value ScalarExprEmitter::emitPromoted(const Expr *E,
case UO_Real:
llvm_unreachable("NYI");
case UO_Minus:
return VisitMinus(UO, PromotionType);
return emitUnaryPlusOrMinus(UO, cir::UnaryOpKind::Minus, PromotionType);
case UO_Plus:
return VisitPlus(UO, PromotionType);
return emitUnaryPlusOrMinus(UO, cir::UnaryOpKind::Plus, PromotionType);
default:
break;
}
Expand Down
Loading