@@ -617,38 +617,26 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
617
617
QualType promotionTy = PromotionType.isNull ()
618
618
? getPromotionType (E->getSubExpr ()->getType ())
619
619
: PromotionType;
620
- auto result = VisitPlus (E , promotionTy);
620
+ auto result = emitUnaryPlusOrMinus (E, cir::UnaryOpKind::Plus , promotionTy);
621
621
if (result && !promotionTy.isNull ())
622
622
return emitUnPromotedValue (result, E->getType ());
623
623
return result;
624
624
}
625
625
626
- mlir::Value VisitPlus (const UnaryOperator *E,
627
- QualType PromotionType = QualType()) {
628
- // This differs from gcc, though, most likely due to a bug in gcc.
629
- TestAndClearIgnoreResultAssign ();
630
-
631
- mlir::Value operand;
632
- if (!PromotionType.isNull ())
633
- operand = CGF.emitPromotedScalarExpr (E->getSubExpr (), PromotionType);
634
- else
635
- operand = Visit (E->getSubExpr ());
636
-
637
- return emitUnaryOp (E, cir::UnaryOpKind::Plus, operand);
638
- }
639
-
640
626
mlir::Value VisitUnaryMinus (const UnaryOperator *E,
641
627
QualType PromotionType = QualType()) {
642
628
QualType promotionTy = PromotionType.isNull ()
643
629
? getPromotionType (E->getSubExpr ()->getType ())
644
630
: PromotionType;
645
- auto result = VisitMinus (E , promotionTy);
631
+ auto result = emitUnaryPlusOrMinus (E, cir::UnaryOpKind::Minus , promotionTy);
646
632
if (result && !promotionTy.isNull ())
647
633
return emitUnPromotedValue (result, E->getType ());
648
634
return result;
649
635
}
650
636
651
- mlir::Value VisitMinus (const UnaryOperator *E, QualType PromotionType) {
637
+ mlir::Value emitUnaryPlusOrMinus (const UnaryOperator *E,
638
+ cir::UnaryOpKind kind,
639
+ QualType PromotionType) {
652
640
TestAndClearIgnoreResultAssign ();
653
641
654
642
mlir::Value operand;
@@ -657,10 +645,12 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
657
645
else
658
646
operand = Visit (E->getSubExpr ());
659
647
648
+ bool nsw =
649
+ kind == cir::UnaryOpKind::Minus && E->getType ()->isSignedIntegerType ();
650
+
660
651
// NOTE: LLVM codegen will lower this directly to either a FNeg
661
652
// or a Sub instruction. In CIR this will be handled later in LowerToLLVM.
662
- return emitUnaryOp (E, cir::UnaryOpKind::Minus, operand,
663
- /* nsw=*/ E->getType ()->isSignedIntegerType ());
653
+ return emitUnaryOp (E, kind, operand, nsw);
664
654
}
665
655
666
656
mlir::Value VisitUnaryNot (const UnaryOperator *E) {
@@ -2334,9 +2324,9 @@ mlir::Value ScalarExprEmitter::emitPromoted(const Expr *E,
2334
2324
case UO_Real:
2335
2325
llvm_unreachable (" NYI" );
2336
2326
case UO_Minus:
2337
- return VisitMinus (UO, PromotionType);
2327
+ return emitUnaryPlusOrMinus (UO, cir::UnaryOpKind::Minus , PromotionType);
2338
2328
case UO_Plus:
2339
- return VisitPlus (UO, PromotionType);
2329
+ return emitUnaryPlusOrMinus (UO, cir::UnaryOpKind::Plus , PromotionType);
2340
2330
default :
2341
2331
break ;
2342
2332
}
0 commit comments