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

Matrix gives llvm error when accessed with non-64-bit int #4284

Open
Up05 opened this issue Sep 21, 2024 · 2 comments
Open

Matrix gives llvm error when accessed with non-64-bit int #4284

Up05 opened this issue Sep 21, 2024 · 2 comments

Comments

@Up05
Copy link

Up05 commented Sep 21, 2024

Context

  • Operating System & Odin Version:
Odin:   dev-2024-08-nightly:8359995
        OS:      CachyOS, Linux 6.10.6-2-cachyos
        CPU:     Quad-Core Processor (up to 1.4GHz)
        RAM:     3354 MiB
        Backend: LLVM 18.1.8

Expected Behavior

The matrix's element is returned

Current Behavior

LLVM CODE GEN FAILED FOR PROCEDURE: main.main
define internal void @main.main(ptr noalias nocapture nonnull %__.context_ptr) {
; [..]
entry:                                            ; preds = %decls
  store i32 1, ptr %_i32, align 4
  %3 = load i32, ptr %_i32, align 4
  %4 = load i32, ptr %_i32, align 4
  %5 = sext i32 %3 to i64
  %6 = sext i32 %4 to i64
  ; [..]

Use of instruction is not an instruction!
  %6 = add i64 %3, %5

Failure Information (for bugs)

It seems to me, that it is assumed, that matrix will only ever be accessed with an i64. (See: last line of LLVM error, i64)

Steps to Reproduce

mat : matrix[4, 4] i64 // whatever* sub-type

main :: proc() {
    _i32 : i32 = 1
    c := mat[_i32, _i32]
    fmt.println(c)
}   

Failure Logs

The rest of LLVM code seems unnecessary.

@pfiadDi
Copy link

pfiadDi commented Sep 21, 2024

(EDIT: works when m is not global)

Get the also a llvm error
Odin: dev-2024-08:d41028176
OS: Ubuntu 22.04.4 LTS, Linux 6.8.0-40-generic
CPU: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
RAM: 39897 MiB
Backend: LLVM 14.0.0

with this code:

package main

import "core:fmt"
import "core:math/rand"
import "core:strings"

l := [dynamic]i64{2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7}

m: matrix[4, 4]i64
nL: i64 = 0
c: i64 = 0
main :: proc() {
	i: i64 = 0
	for 0 < 16 {
		nL = choose_number()
		switch i {
		case 0 ..< 4:
			m[0, c] = nL
		case 4 ..< 8:
			c = i - 4
			m[1, c] = nL
		case 8 ..< 12:
			c = i - 8
			m[2, c] = nL
		case 12 ..< 16:
			c = i - 12
			m[3, c] = nL
		}
	}

	fmt.println(m)
}

choose_number :: proc() -> i64 {
		if len(l) == 1 {return l[0]}
	randIndex := rand.int31_max(cast(i32)len(l))
	newLetter := l[randIndex]
	unordered_remove(&l, cast(int)randIndex)
	return newLetter
}


Here' the beginning of the error:
LLVM CODE GEN FAILED FOR PROCEDURE: main.main
define internal void @main.main(i8* noalias nocapture nonnull %__.context_ptr) {
decls:
%i = alloca i64, align 8
%0 = alloca { %..any*, i64 }, align 8
%1 = alloca [16 x i8], align 16
%2 = alloca %..any, align 8
br label %entry

entry: ; preds = %decls
%3 = bitcast i8* %__.context_ptr to %runtime.Context*
store i64 0, i64* %i, align 8
br label %for.loop

for.loop: ; preds = %switch.done, %entry
br i1 true, label %for.body, label %for.done

for.body: ; preds = %for.loop
%4 = bitcast %runtime.Context* %3 to i8*
%5 = call i64 @main.choose_number(i8* %4)
store i64 %5, i64* @main.nL, align 8
%6 = load i64, i64* %i, align 8
%7 = icmp sle i64 0, %6
%8 = icmp slt i64 %6, 4
%9 = zext i1 %7 to i8
%10 = zext i1 %8 to i8
%11 = and i8 %9, %10
%12 = trunc i8 %11 to i1
br i1 %12, label %switch.case.body, label %switch.case.next

...

@FourteenBrush
Copy link
Contributor

This only seems to be caused when the matrix is a global variable, however, the following code runs fine:

package bug

mat: matrix[4, 4]i64

main :: proc() {
    c := mat[i32(0), i32(0)]
}

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