[clang] [CIR] Implement simple folding for unary operations (PR #174882)
Sirui Mu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 8 06:48:55 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>()) {
----------------
Lancern wrote:
> 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?
I didn't quite know how MLIR would actually fold a sequence of operations. My guess was, given a sequence of CIR operations such as:
```
```
https://github.com/llvm/llvm-project/pull/174882
More information about the cfe-commits
mailing list