Skip to content

Never inline intrinsic functions #1709

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

Merged
merged 2 commits into from
Apr 16, 2023
Merged

Never inline intrinsic functions #1709

merged 2 commits into from
Apr 16, 2023

Conversation

gptsarthak
Copy link
Contributor

Fixes #1698

import time
import random
import math

print(time.time())
print(random.randrange(10,20))
print(random.random())
print(math.atanh(0.90))

Main:

(lp) sarthak@pop-os:~/lpython$ lpython --fast examples/time.py
0.00000000000000000e+00
0
9.53282412436823800e-130
9.53282412436823800e-130

On branch:

(lp) sarthak@pop-os:~/lpython_new/lpython$ src/bin/lpython --fast examples/hi.py
1.68139046414960361e+09
13
3.94382926819093038e-01
1.47221948958322035e+00

@gptsarthak
Copy link
Contributor Author

There is no harm in doing this since all functions whose name starts with _lfortran_ are intrinsic.
This might just be a temporary fix, until the problem in #1698 (comment) is fixed.

@certik
Copy link
Contributor

certik commented Apr 14, 2023

Thanks for the workaround!

I would rather fix this properly. The runtime library has a few hacks in the code base and this PR feels to me like it is adding another hack. I would rather remove some hacks, or add them into one place and wrap them in some functions.

If the problem is that we can't reliably identify intrinsic functions, then let's fix that.

@gptsarthak gptsarthak marked this pull request as draft April 14, 2023 09:18
@gptsarthak
Copy link
Contributor Author

I guess we just have have to find a way so that functions that are coming from imported modules do not get inlined. @czgdp1807 do you know anything about that?

@czgdp1807
Copy link
Collaborator

I guess we just have have to find a way so that functions that are coming from imported modules do not get inlined.

Why so? If we are able to access the body of the function in ASR then I think inlining should be possible and we should do it. Probably that would be the proper fix instead of avoiding inlining them. Let's do it here and see what blocks us from properly inlining them. The only case which needs avoiding inlining is those functions which contain fallback implementations of optimisations such as flip_sign, etc, specifically, https://github.com/lfortran/lfortran/blob/main/src/runtime/builtin/lfortran_intrinsic_optimization.f90.

@gptsarthak
Copy link
Contributor Author

But we cannot inline functions which are implemented in C using @ccall am I wrong?

@certik
Copy link
Contributor

certik commented Apr 14, 2023

For BindC functions, we can inline the function call. Obviously we can't inline the function itself, since we don't have the source code.

@gptsarthak
Copy link
Contributor Author

Is this alright? We stop inlining BindC function after we have inlined its fuction call.
--fast works alright with this fix.

@certik certik requested a review from czgdp1807 April 16, 2023 14:23
@czgdp1807 czgdp1807 marked this pull request as ready for review April 16, 2023 14:25
@czgdp1807 czgdp1807 enabled auto-merge (squash) April 16, 2023 14:26
@czgdp1807 czgdp1807 merged commit 81ca86b into lcompilers:main Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lfortran_intrinsics do not work with --fast
3 participants