Case expressions allocate a temporary variable to hold the value of the input expression, even if the input expression is actually a user-defined variable. This optimization detects these instances, removes the temporary variable, and replaces it with the original variable containing the value of the input expression. The set instruction is removed, while the other instructions are updated to replace the temporary variable with the one used in the set statement.
The optimization is performed only when the following conditions are met:
- The set instruction assigns to a case-expression temporary variable.
- The set instruction is the first of all those using the temporary variable (the check is based on the absolute instruction sequence in the program, not on the actual program flow).
- Each following instruction using the temporary variable conforms to the code generated by the compiler (i.e., has the form of
jump target <condition> *tmpX testValue)
« Previous: Boolean Optimization | Up: Code optimization | Next: Case Switching »