likun666661 opened a new pull request, #50372: URL: https://github.com/apache/arrow/pull/50372
### Rationale for this change This adds a conservative Gandiva expression-layer common subexpression folding pass before code generation. Repeated pure expression subtrees can otherwise be decomposed and lowered multiple times before LLVM sees the module. The pass intentionally avoids cases where expression-level reuse can be unsafe, including functions that need execution context/function holders, can return errors, use result-null-internal handling, and boolean/if decomposition results with local validity bitmap side effects. ### What changes are included in this PR? - Add `expr_cse` to fold safe repeated Gandiva expression subtrees before projector/filter code generation. - Add decomposition reuse for safe field, literal, and pure function nodes. - Expose unoptimized IR dumping for Gandiva tests when `dump_ir` is enabled. - Add IR-focused tests covering nested arithmetic, generated `if`, generated boolean, and nested `between`-style patterns. ### Are these changes tested? Yes. ```console $ git diff --check $ pre-commit run --show-diff-on-failure --color=always --all-files cpp $ PYTHON=/opt/homebrew/bin/python3 TZ=UTC ARROW_TEST_DATA=/Users/likun/workspace-for-apache-arrow/testing/data ninja -C cpp/build-gandiva unittest ``` The `ninja ... unittest` run completed with `100% tests passed, 0 tests failed out of 81`. ### AI-assisted contribution disclosure This PR was prepared with AI assistance. I reviewed and tested the generated changes locally, including the Gandiva C++ tests and Arrow C++ pre-commit checks listed above. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
