Skip to content

[Bug]: High-Level dialects leaking to LLVM mlir representations #774

@kumarak

Description

@kumarak

VAST version

v0.0.66

LLVM version

19.1.0

Operating system

macos

Description

I see many of the high-level dialects leaking to LLVM IR representations after running vast passes. Some of them I can easily reproduce like hl.ref, hl.addressof, hl.implicit_cast, hl.bitcast. The conversion pattern does not catch all and apply conversion fully.

test_addr.c:7:23: error: unexpected error: failed to materialize conversion for result #0 of operation 'hl.implicit_cast' that remained live after conversion
        ptrofptr[i] = ptrs + i;
                      ^
test_addr.c:7:23: error: unexpected note: see current operation: %56 = "hl.implicit_cast"(%2) {kind = 11 : i64} : (!hl.ptr<!hl.array<10, !hl.ptr<si32>>>) -> !hl.ptr<!hl.ptr<si32>>
        ptrofptr[i] = ptrs + i;
                      ^
test_addr.c:7:28: error: unexpected note: see existing live user here: %59 = "llvm.bitcast"(%56) : (!hl.ptr<!hl.ptr<si32>>) -> i64
        ptrofptr[i] = ptrs + i;
                           ^
// -----// IR Dump After IRsToLLVM Failed (vast-irs-to-llvm) //----- //
module {
  core.module @"/Users/akshayk/Documents/workspace/demo/vast/build/test_addr.c" attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<!hl.array<10, !hl.ptr<!hl.ptr<si32>>>, {vast.abi_align.key = 64 : i32, vast.dl.bw = 640 : i32}>, #dlti.dl_entry<!hl.ptr<!hl.ptr<!hl.ptr<si32>>>, {vast.abi_align.key = 64 : i32, vast.dl.bw = 64 : i32}>, #dlti.dl_entry<!hl.ptr<!hl.ptr<si32>>, {vast.abi_align.key = 64 : i32, vast.dl.bw = 64 : i32}>, #dlti.dl_entry<!hl.ptr<si32>, {vast.abi_align.key = 64 : i32, vast.dl.bw = 64 : i32}>, #dlti.dl_entry<!hl.array<10, !hl.ptr<si32>>, {vast.abi_align.key = 64 : i32, vast.dl.bw = 640 : i32}>>, vast.core.lang = #core<lang c>, vast.core.target_triple = "arm64-apple-macosx15.0.0"} {
    hl.var @num, <external>  : !hl.ptr<si32> = {
      %0 = hl.const #core.integer<10> : si32
      hl.value.yield %0 : si32
    }
    ll.func @test external () -> si32 {
      %0 = ll.alloca : !hl.ptr<!hl.array<10, !hl.ptr<si32>>>
      %1 = hl.const #core.integer<0> : si32
      %2 = hl.implicit_cast %1 NullToPointer : si32 -> !hl.ptr<si32>
      %3 = hl.initlist %2 : (!hl.ptr<si32>) -> !hl.array<10, !hl.ptr<si32>>
      ll.store %0, %3 : !hl.ptr<!hl.array<10, !hl.ptr<si32>>>, !hl.array<10, !hl.ptr<si32>>
      %4 = ll.alloca : !hl.ptr<!hl.array<10, !hl.ptr<!hl.ptr<si32>>>>
      %5 = hl.const #core.integer<0> : si32
      %6 = hl.implicit_cast %5 NullToPointer : si32 -> !hl.ptr<!hl.ptr<si32>>
      %7 = hl.initlist %6 : (!hl.ptr<!hl.ptr<si32>>) -> !hl.array<10, !hl.ptr<!hl.ptr<si32>>>
      ll.store %4, %7 : !hl.ptr<!hl.array<10, !hl.ptr<!hl.ptr<si32>>>>, !hl.array<10, !hl.ptr<!hl.ptr<si32>>>
      %8 = ll.alloca : !hl.ptr<si32>
      %9 = hl.const #core.integer<0> : si32
      ll.store %8, %9 : !hl.ptr<si32>, si32
      core.scope {
        ll.br ^bb2
      ^bb1:  // pred: ^bb3
        %11 = ll.load %8 : (!hl.ptr<si32>) -> si32
        %12 = hl.const #core.integer<1> : si32
        %13 = hl.add %11, %12 : (si32, si32) -> si32
        ll.store %8, %13 : !hl.ptr<si32>, si32
        ll.br ^bb2
      ^bb2:  // 2 preds: ^bb0, ^bb1
        %14 = ll.load %8 : (!hl.ptr<si32>) -> si32
        %15 = hl.const #core.integer<10> : si32
        %16 = hl.cmp slt %14, %15 : si32, si32 -> si32
        %17 = hl.implicit_cast %16 IntegralCast : si32 -> i1
        ll.cond_scope_ret %17 : i1, ^bb3
      ^bb3:  // pred: ^bb2
        %18 = hl.implicit_cast %0 ArrayToPointerDecay : !hl.ptr<!hl.array<10, !hl.ptr<si32>>> -> !hl.ptr<!hl.ptr<si32>>
        %19 = ll.load %8 : (!hl.ptr<si32>) -> si32
        %20 = ll.subscript %18 at [%19 : si32] : !hl.ptr<!hl.ptr<si32>> -> !hl.ptr<!hl.ptr<si32>>
        %21 = hl.ref @num : !hl.ptr<si32>
        %22 = hl.addressof %21 : !hl.ptr<si32> -> !hl.ptr<si32>
        ll.store %20, %22 : !hl.ptr<!hl.ptr<si32>>, !hl.ptr<si32>
        %23 = hl.implicit_cast %4 ArrayToPointerDecay : !hl.ptr<!hl.array<10, !hl.ptr<!hl.ptr<si32>>>> -> !hl.ptr<!hl.ptr<!hl.ptr<si32>>>
        %24 = ll.load %8 : (!hl.ptr<si32>) -> si32
        %25 = ll.subscript %23 at [%24 : si32] : !hl.ptr<!hl.ptr<!hl.ptr<si32>>> -> !hl.ptr<!hl.ptr<!hl.ptr<si32>>>
        %26 = hl.implicit_cast %0 ArrayToPointerDecay : !hl.ptr<!hl.array<10, !hl.ptr<si32>>> -> !hl.ptr<!hl.ptr<si32>>
        %27 = ll.load %8 : (!hl.ptr<si32>) -> si32
        %28 = hl.add %26, %27 : (!hl.ptr<!hl.ptr<si32>>, si32) -> !hl.ptr<!hl.ptr<si32>>
        ll.store %25, %28 : !hl.ptr<!hl.ptr<!hl.ptr<si32>>>, !hl.ptr<!hl.ptr<si32>>
        ll.br ^bb1
      }
      %10 = hl.const #core.integer<0> : si32
      ll.return %10 : si32
    }
  }
}


[VAST fatal] MLIR pass manager failed when running vast passes

Steps to Reproduce

Can be reproduced with following snippet

int num = 10;
int test() {
    int *ptrs[10] = {0,};
    int **ptrofptr[10] = {0,};
    for (int i = 0; i < 10; i++) {
        ptrs[i] =  &num;
        ptrofptr[i] = ptrs + i;
    }
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions