================
@@ -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'll try a rewrite using the adaptor. That should be quick to implement, and it 
seems to be a more standard way of doing things. I've implemented the next step 
(folding during CG) in my sandbox, and I can verify that doing it that way does 
create the constants in the order suggested above and leaves a dead constant 
behind. The dead constant seems to be cleaned up if I wait until 
`CIRCanonicalize`, but for some reason `createOrFold` leaves it behind.

https://github.com/llvm/llvm-project/pull/174882
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to