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

Bad codegen for negative types on LLVM #801

Open
jiribenes opened this issue Jan 24, 2025 · 0 comments
Open

Bad codegen for negative types on LLVM #801

jiribenes opened this issue Jan 24, 2025 · 0 comments
Labels
area:llvm bug Something isn't working

Comments

@jiribenes
Copy link
Contributor

Extracted from #795 (comment)

Hypothesis: The LLVM backend has bad codegen for negative types.

Here are the two test cases that fail:

$ EFFEKT_DEBUG=1 effekt --backend=llvm --ir-write-all --debug --optimize examples/stdlib/json.effekt
opt: ./out/json.ll:4001:9: error: multiple definition of local value named 'd_24_132_3_22162'
        %d_24_132_3_22162 = insertvalue %Neg %vtable_temporary_865, %Object %closure_861, 1
        ^

$ EFFEKT_DEBUG=1 effekt --backend=llvm --ir-write-all --debug --optimize examples/stdlib/buffer.effekt
Instruction does not dominate all uses!
  %buffer_24_4387 = insertvalue %Neg %vtable_temporary_1257, ptr %closure_1239, 1
  call void @shareNegative(%Neg %buffer_24_4387)
Instruction does not dominate all uses!
  %buffer_24_4387 = insertvalue %Neg %vtable_temporary_1257, ptr %closure_1239, 1
  store %Neg %buffer_24_4387, ptr %buffer_24_4387_pointer_1255, align 8, !noalias !0
Instruction does not dominate all uses!
  %buffer_24_4387 = insertvalue %Neg %vtable_temporary_1257, ptr %closure_1239, 1
  call void @eraseNegative(%Neg %buffer_24_4387)
opt: ./out/buffer.ll: error: input module is broken!

Analysis

I think it's the same problem, actually.
For negative types, we generate:

define tailcc void @xyz_clause_1(...) { ... }
define tailcc void @xyz_clause_2(...) { ... }

which always share what would be:

; new xyz_clause_6769, 0 parameters
        %xyz_6769_pointer_492 = getelementptr {%reference, %reference, %neg, %pos, i64}, %environment %environment_489, i64 0, i32 2
        %xyz_6769 = load %neg, ptr % xyz_6769_pointer_492, !noalias !2

so the same value is defined under the same name in multiple different functions.

@jiribenes jiribenes added bug Something isn't working area:llvm labels Jan 24, 2025
jiribenes added a commit that referenced this issue Jan 24, 2025
Resolves #614 by adding a stdlib test that imports every single (common)
stdlib module.

Let's add [ACME](https://en.wikipedia.org/wiki/Acme_Corporation) (in our
context "All Common Modules in Effekt" :)) to the stdlib tests: just
import and compile all modules.

This revealed 3 different bugs in stdlib + codegen bugs on LLVM (moved
to #801).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:llvm bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant