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

hang in ir_sccp #101

Open
sgraham opened this issue Jan 18, 2025 · 0 comments
Open

hang in ir_sccp #101

sgraham opened this issue Jan 18, 2025 · 0 comments

Comments

@sgraham
Copy link

sgraham commented Jan 18, 2025

I'm running into a hang in ir_sccp() on Windows amd64, ir_builder repro below.

It seems to get stuck in this loop, ir_sccp.c:~2232 but I'm not sure what invariant has been violated.

	while ((i = ir_bitqueue_pop(&worklist)) >= 0) {

The hang only happens in this repro if there's 8 CALLs, if I e.g. remove the last one, it works as expected. (Of course it also works at with optimizations disable as ir_sccp() is skipped).

#include <stdlib.h>
#include "ir.h"
#include "ir_builder.h"

#include <stdio.h>

void printer(int32_t value) {
  printf("%d\n", value);
}

void gen_myfunc(ir_ctx* ctx) {
  ir_START();

  ir_ref a = ir_VAR(IR_I32, "a");
  ir_VSTORE(a, ir_CONST_I32(1));

  ir_ref b = ir_VAR(IR_I32, "b");
  ir_VSTORE(b, ir_CONST_I32(2));

  ir_ref c = ir_VAR(IR_I32, "c");
  ir_VSTORE(c, ir_CONST_I32(3));

  ir_ref d = ir_VAR(IR_I32, "d");
  ir_VSTORE(d, ir_CONST_I32(4));

  ir_ref e = ir_VAR(IR_I32, "e");
  ir_VSTORE(e, ir_CONST_I32(5));

  ir_ref f = ir_VAR(IR_I32, "f");
  ir_VSTORE(f, ir_CONST_I32(6));

  ir_ref g = ir_VAR(IR_I32, "g");
  ir_VSTORE(g, ir_CONST_I32(7));

  ir_ref h = ir_VAR(IR_I32, "h");
  ir_VSTORE(h, ir_CONST_I32(8));

  ir_ref print_addr = ir_CONST_ADDR(printer);
  ir_CALL_1(IR_VOID, print_addr, ir_VLOAD(IR_I32, a));
  ir_CALL_1(IR_VOID, print_addr, ir_VLOAD(IR_I32, b));
  ir_CALL_1(IR_VOID, print_addr, ir_VLOAD(IR_I32, c));
  ir_CALL_1(IR_VOID, print_addr, ir_VLOAD(IR_I32, d));
  ir_CALL_1(IR_VOID, print_addr, ir_VLOAD(IR_I32, e));
  ir_CALL_1(IR_VOID, print_addr, ir_VLOAD(IR_I32, f));
  ir_CALL_1(IR_VOID, print_addr, ir_VLOAD(IR_I32, g));
  ir_CALL_1(IR_VOID, print_addr, ir_VLOAD(IR_I32, h));

  ir_RETURN(IR_UNUSED);
}

int main(int argc, char** argv) {
  ir_ctx ctx;

  ir_consistency_check();

  ir_init(&ctx, IR_FUNCTION | IR_OPT_FOLDING, IR_CONSTS_LIMIT_MIN, IR_INSNS_LIMIT_MIN);
  ctx.ret_type = IR_VOID;

  gen_myfunc(&ctx);

  size_t size;
  void* entry = ir_jit_compile(&ctx, 2, &size);
  if (entry) {
    ((void (*)())entry)();
  }

  ir_free(&ctx);

  return 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

1 participant