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

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 8 11:21:44 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>()) {
----------------
andykaylor wrote:

> I believe standarc MLIR canonicalize pass uses dead code analysis for everythng once it is finished, so one does not need to do redundant clean up implementation.

Near as I can tell, it only removes values that become dead during folding. If we introduce dead constants during codegen, we need to explicitly clean them up during our canonicalize pass or run a separate dead value elimination pass.

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


More information about the cfe-commits mailing list