effekt-lang / effekt-lang/effekt

Bad codegen for negative types on LLVM

Open
#801 0 comments 0 reactions 1 assignee Claimed by @phischu View on GitHub
area:llvm bug
Dominant language
Scala
Stars
469
Forks
41
Avg merge
1d 16h
Merged PRs (30d)
23

Description

_Extracted from https://github.com/effekt-lang/effekt/issues/795#issuecomment-2609496261_

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.