Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 394
    • Issues 394
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 17
    • Merge requests 17
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Merge requests
  • !285

Unmodified Return Removal

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Jordy Aaldering requested to merge unmodified-return-removal into develop Feb 21, 2024
  • Overview 11
  • Commits 15
  • Changes 21

With this optimisation we 'remove' return types whose values are the same as one of the arguments. I.e., the returned value is unchanged. A prominent example of this is the identity function.

If we encounter an application that has an unmodified return type, we lookup which actual argument corresponds to that return value and replace any following uses of that return value by that actual argument (N_id) instead. Consider the following example:

int main() {
    a = 37;
    b = 42;
    c = second (a, b);
    return c;
}

Where second returns the second value of the two given arguments. Because this function keeps that return value unchanged, the N_ret is marked as being the same as its second argument, after which any occurences of c can be replaced by b.

int main() {
    a = 37;
    b = 42;
    c = second (a, b); // can now be removed by dead code removal
    return b;          // c becomes b
}

Requires a new identity function in mini-stdlib.sac to avoid fusion in tests, because this optimisation breaks some tests otherwise.

Edited Mar 07, 2024 by Jordy Aaldering
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: unmodified-return-removal