MATLAB: Does expression folding not work when inlining a custom S-function with custom TLC in Real-Time Workshop 7.4 (R2009b)

simulink coder

I have a custom S-function and have written a custom TLC file for that. However, even after calling the function LibBlockSetIsExpressionCompliant(block), expression folding does not seem to be working if the S-function is inlined.
However, if I do not inline the S-function and create a separate function, then the expression folding works.

Best Answer

Expression folding is an optimization and the TLC functions and flags in S-functions can only request for it.
Expression folding depends on a lot of other factors like the position of the S-function in model i.e. whether it is at the root level or inside other subsystem(s) besides these flags. As a result, there may be a hierarchy of properties/rules that may need to be applied and there is no guarantee that the request for expression folding will be honored.