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

Backend: incorrect register allocation #19

Open
atirut-w opened this issue Dec 6, 2024 · 1 comment
Open

Backend: incorrect register allocation #19

atirut-w opened this issue Dec 6, 2024 · 1 comment
Assignees

Comments

@atirut-w
Copy link
Owner

atirut-w commented Dec 6, 2024

This is most likely a fundamental bug with the register allocator and codegen, even more so how they're designed.

The root cause of this issue is that in LLVM, constants with the same type and value have the same pointer, and the allocator uses a map<Value *, reg> to store register allocation information. The allocation algorithm allocates by iterating through instructions in reverse and allocating its operands depending on the opcode. Of course, this means that if there are constants with the same type and value, the old one would be overwritten.

Help needed.

Input:

; int main(int argc, char *argv[])
define i16 @main(i16 %argc, i8** nocapture %argv) {
  %1 = add i16 2, 2
  ret i16 %1
}

Output:

	; Generated by ZDK C Compiler

	.global main
main:
0:
;   %1 = add i16 2, 2
	ld de, 2
	ld de, 2
	add de, de
;   ret i16 %1
	ret
@atirut-w atirut-w assigned atirut-w and unassigned atirut-w Dec 6, 2024
@atirut-w
Copy link
Owner Author

Think I figured out a fix now, with the sacrifice being more spilled values.

@atirut-w atirut-w self-assigned this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant