[clang] [CIR] Fold unary operations and simple casts (PR #174670)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 6 17:08:39 PST 2026


================
@@ -781,9 +841,26 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
     return result;
   }
 
+  mlir::Value foldUnaryOp(const UnaryOperator *e) {
+    Expr::EvalResult result;
+    if (!e->EvaluateAsRValue(result, cgf.getContext()))
----------------
andykaylor wrote:

Also, a question about your statement that doing it the way I currently am will be slower.... The alternative is to visit the expression and emit the constant (and possibly intermediate casts?) before we attempt to fold it, so that's basically also walking the AST while also creating intermediate artifacts that might be avoided by calling `EvaluateAsRValue`, right?

https://github.com/llvm/llvm-project/pull/174670


More information about the cfe-commits mailing list