[clang] [CIR] Implement simple folding for unary operations (PR #174882)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 8 06:20:54 PST 2026


================
@@ -2479,6 +2479,39 @@ OpFoldResult cir::UnaryOp::fold(FoldAdaptor adaptor) {
       if (isBoolNot(previous))
         return previous.getInput();
 
+  // Fold constant unary operations.
+  if (auto srcConst = getInput().getDefiningOp<cir::ConstantOp>()) {
----------------
erichkeane wrote:

I might suggest we do a `TypeSwitch` if we're doing something like that.  That said, WHICH direction we go (switch on kind, then type, vs type then kind) doesn't seem particularly motivated in 1 way or the other?

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


More information about the cfe-commits mailing list