[MLIR][SCCP] Fix in-place folds leaking into IR during simulation (#213933)

SparseConstantPropagation restored the operation only when `fold` did
not return any fold results. But a folder can mutate the op in place and
still return out-of-place results or fail, e.g. `vector.extract` folds
constant dynamic positions into static ones before attempting further
folds.
The constants fed to `fold` are speculative lattice values, so the
mutation bakes a possibly-wrong constant into the IR. SCCP would
permanently replace a loop-carried dynamic index with its first lattice
value for example.

Fix: Restore the original operands and attributes after every fold call,
regardless of its outcome.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
GitOrigin-RevId: dce57cf279d65b0ce871a77f1b493e5141a99379
2 files changed
tree: 04cbf9335c9cedf99d414d6eedc2c2535c2b6432
  1. benchmark/
  2. cmake/
  3. docs/
  4. examples/
  5. include/
  6. lib/
  7. python/
  8. test/
  9. tools/
  10. unittests/
  11. utils/
  12. .clang-format
  13. .clang-tidy
  14. CMakeLists.txt
  15. LICENSE.TXT
  16. Maintainers.md
  17. README.md
README.md

Multi-Level Intermediate Representation

See https://mlir.llvm.org/ for more information.