Skip to content

[BUG] LayoutTensor matmul fails at -O0 with llvm.masked.load alignment error #5944

@TheAgaveFairy

Description

@TheAgaveFairy

Bug description

Actual behavior

Using linalg.matmul matmul() with -O0 fails to compile:

mojo build -O0 main.mojo

oss/modular/mojo/stdlib/std/sys/intrinsics.mojo:78:10: error: llvm.masked.load alignment must be a constant, got runtime value
oss/modular/mojo/stdlib/std/sys/intrinsics.mojo:554:65: note: called from
oss/modular/mojo/stdlib/std/sys/intrinsics.mojo:78:10: note: see current operation: %16879 = "pop.call_llvm_intrinsic"(%16877) <{fastmathFlags = #pop, hasSideEffects = true, intrin = "llvm.masked.load" : !kgen.string}> : (!kgen.struct<(pointer, scalar, simd<16, bool>, simd<16, f32>)>) -> !pop.simd<16, f32>
oss/modular/mojo/stdlib/std/sys/intrinsics.mojo:78:10: error: failed to legalize operation 'pop.call_llvm_intrinsic' that was explicitly marked illegal
oss/modular/mojo/stdlib/std/sys/intrinsics.mojo:554:65: note: called from
oss/modular/mojo/stdlib/std/sys/intrinsics.mojo:78:10: note: see current operation: %16878 = "pop.call_llvm_intrinsic"(%16877) <{fastmathFlags = #pop, hasSideEffects = true, intrin = "llvm.masked.load" : !kgen.string}> : (!kgen.struct<(pointer, scalar, simd<16, bool>, simd<16, f32>)>) -> !pop.simd<16, f32>

(this goes on for some time...)

Expected behavior

Compile without error.

Steps to reproduce

Compiles with -01 and above, -O0 fails for my debug builds.

from linalg.matmul import matmul
from layout import Layout, LayoutTensor
from benchmark.compiler import keep

comptime layout = Layout.row_major(5, 5)
comptime Matrix = LayoutTensor[DType.float32, layout, MutAnyOrigin]

def main():
    var a = Matrix.stack_allocation().fill(1.0)
    var b = Matrix.stack_allocation().fill(1.0)
    var c = Matrix.stack_allocation().fill(0.0)

    matmul(c, a, b, None)
    keep(c)

System information

  • Provide the system information by running pixi info.
  • Provide version information for MAX (includes Mojo) by pasting the output of pixi list max.
    System

   Pixi version: 0.48.2
       Platform: linux-64

Virtual packages: __unix=0=0
: __linux=6.17.0=0
: __glibc=2.39=0
: __cuda=13.1=0
: __archspec=1=zen4
Cache dir: /home/paul-dutton/.cache/rattler/cache
Auth storage: /home/paul-dutton/.rattler/credentials.json
Config locations: /home/paul-dutton/.pixi/config.toml

Global

        Bin dir: /home/paul-dutton/.pixi/bin
Environment dir: /home/paul-dutton/.pixi/envs
   Manifest dir: /home/paul-dutton/.pixi/manifests/pixi-global.toml

Workspace

           Name: mojollm
        Version: 0.1.0
  Manifest file: /home/paul-dutton/Documents/GitHub/mojollm/pixi.toml
   Last updated: 12-02-2026 22:07:12

Environments

    Environment: default
       Features: default
       Channels: https://conda.modular.com/max-nightly, conda-forge

Dependency count: 2
Dependencies: mojo, max
Target platforms: linux-64
Prefix location: /home/paul-dutton/Documents/GitHub/mojollm/.pixi/envs/default

Package Version Build Size Kind Source
max 26.2.0.dev2026021205 3.14release 5.8 MiB conda https://conda.modular.com/max-nightly/
max-core 26.2.0.dev2026021205 release 122.6 MiB conda https://conda.modular.com/max-nightly/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssue needs to be routed/triaged to a particular team stillbugSomething isn't workingmojoIssues that are related to mojo

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions