[Mlir-commits] [mlir] [mlir][emitc] Inline constant when translate (PR #143485)
Gil Rapaport
llvmlistbot at llvm.org
Sat Jun 14 09:38:31 PDT 2025
aniragil wrote:
>A constant op, such as emitc.constant, will be moved out to the parent region during applying patterns because of constant CSE. If we add CExpression to emitc.constant, In the FormExpressions pass, we will get an empty expression with only terminator yield.
Right, though being sort of a "prepare for translation" transformation, `form-expressions` is meant to run after all other transformations, which is why it only inlines single-use expressions, avoiding re-materialization that would undo deduplication. We could however make `emitc.expression` IsolatedFromAbove, which IINM would prevent CSE from simplifying it out of the expression. This would both allow `form-expressions` to run at any point in the pipeline and allow lowering passes to generate expressions safely if desired. WDYT?
> One could argue that the emitc.constant shouldn't have the ConstantLike trait as it's emitted as local variables and thus has side effects. What's your opinion on this @marbre @aniragil @mgehre-amd?
>
> That would also be disruptive downstream though as constants wouldn't be deduplicated anymore.
IINM `emitc.constant` is emitted as an "SSA" C variable rather than an lvalue variable, so it doesn't have side effects in the MLIR sense. BTW, might also be good to have more `emitc` ops (notably operators) have the `pure` trait for better CSE/DCE behavior.
https://github.com/llvm/llvm-project/pull/143485
More information about the Mlir-commits
mailing list