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

Intrinsics handling. Again. #1551

Open
vext01 opened this issue Jan 16, 2025 · 4 comments
Open

Intrinsics handling. Again. #1551

vext01 opened this issue Jan 16, 2025 · 4 comments
Assignees

Comments

@vext01
Copy link
Contributor

vext01 commented Jan 16, 2025

Using today's master at 47aad5c with this lua program:

C = {}
function C.new()
	return setmetatable(C, {})
end
function C:math()
end
function a()
	B = {}
	for a = 1, 51 do
		B[a] = C.new()
	end
	for _ = 0, 177 do
		for a = 1, 51 do
			B[a]:math()
		end
	end
end
for _ = 0, 1 do
   a()
end

The log shows:

$ YK_LOG=4 YKD_SERIALISE_COMPILATION=1 /home/vext01/research/yklua/src/lua/bounce.lua.bak
yk-jit-event: start-tracing
yk-warning: stop-tracing-aborted: Trace too long
yk-jit-event: start-tracing
yk-jit-event: stop-tracing
yk-warning: trace-compilation-aborted: dlsym("llvm.memcpy.p0.p0.i64") returned NULL
yk-jit-event: start-tracing
yk-jit-event: stop-tracing
yk-warning: trace-compilation-aborted: Trace too long.

yk-warning: trace-compilation-aborted: dlsym("llvm.memcpy.p0.p0.i64") returned NULL

Here we obviously can't find a symbol by that name. If we are going to do a call, it should be to memcpy.

However, @ptersilie rightly points out that if the intrinsic was inlined, doing the call would be incorrect.

So what we have currently is actually good because it's sound, but could we handle the intrinsic properly and not abort tracing somehow?

Related: #817

@ltratt
Copy link
Contributor

ltratt commented Jan 16, 2025

I don't see the evidence that what we're doing is sound or unsound: you need to look at the trace to see if the call has been inlined/not-inlined and/or call added.

@vext01
Copy link
Contributor Author

vext01 commented Jan 16, 2025

Note that we would be talking about LLVM inlining the intrinsic at the MIR level.

The intrinsic call will always be present in the high level IR.

@ptersilie
Copy link
Contributor

I agree with @ltratt. There could be cases where LLVM has inlined the call in some blocks but not in others. So we do find the symbol with dlsym, so we don't abort the trace, but then in the trace we don't know which calls were inlined and which weren't.

@ptersilie
Copy link
Contributor

From an offline discussion: At the moment we reject calls we don't find the symbol for. For now this is sound if LLVM never emits calls to functions with the same name as the intrinsic. E.g. llvm.memcpy.p0.p0.i64 is probably fine since LLVM emits memcpy calls for it. But we don't know if that's the case of all intrinsics. As a temporary hack, we could put a debug_assert in trace_builder that checks we never try to emit an indirect call that starts with llvm..

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

No branches or pull requests

3 participants