About LetStmtNode elimination in ScheduleOps

Hi, I have a question about LetStmtNode elimination in ScheduleOps.

Currently, in ScheduleOps, the SchedulePostProc will eliminate LetStmtNode if there is no side effect in the ‘value’ of a LetStmtNode. The SchedulePostProc achieves this by replacing ‘var’ with ‘value’.

However, ‘value’ can be a complex experssion even it has no side effect. For example, consider the following TIR program before ScheduleOps:

Let taskId = ax + by + z

func1(…, taskId, …)

func2(…, taskId, …)

func3(… taskId, …)

After ScheduleOps, the ‘taskId’ in the example above will be replaced by ‘ax + by + z’.

The problem here is that the expression ‘ax + by + z’ may be evaluated several times where the variable ‘taskId’ appears. If we do not replace ‘taskId’ with its ‘value’, this problem can be avoided.

I know that some compilers may optimize this with techniques like CSE. However, is it better not to do LetStmtNode elimination for 'value’s that are complex experssions?