Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize recursive calls when unoptimizable branches are present in the return path #1

Open
Sipkab opened this issue Apr 14, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@Sipkab
Copy link
Owner

Sipkab commented Apr 14, 2020

There may be cases when a tail recursive call has multiple execution paths after the call itself. The optimization should be performed in cases where it is possible.

One example is such:

public static int count(int n) {
	if (n == 0) {
		return 0;
	}
	int v = count(n - 1);
	if (n == 0) {
		callSomeOtherMethod();
	}
	return v;
}

Should be optimized to:

public static int count(int n) {
start:
	if (n == 0) {
		return 0;
	}
	
	if (n == 0) {
		int v = count(n - 1);
		callSomeOtherMethod();
		return v;
	}
	n = n - 1;
	goto start;
}

Current state

Currently we allow branches to be present in the return path, but they all need to be side-effect free. This issue requires individual modifications and analysis to the subsequent execution paths.

@Sipkab Sipkab added the enhancement New feature or request label Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant