The pass tried to fold in reverse-post-order, but it cause an issue
when a parent is folded before the chilren as they will still be
present in the worklist.
Use reverse-preorder instead here.
Fixes #64089
// Collect and fold the operations within the operation.
SmallVector<Operation *, 8> ops;
- getOperation()->walk([&](Operation *op) { ops.push_back(op); });
+ getOperation()->walk<mlir::WalkOrder::PreOrder>([&](Operation *op) { ops.push_back(op); });
// Fold the constants in reverse so that the last generated constants from
// folding are at the beginning. This creates somewhat of a linear ordering to