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

[Bug] Incorrect scf.for code is generated #386

Open
menghaining opened this issue Feb 17, 2024 · 0 comments
Open

[Bug] Incorrect scf.for code is generated #386

menghaining opened this issue Feb 17, 2024 · 0 comments

Comments

@menghaining
Copy link

The following C code generates wrong mlir code

int foo(int num) {
  int sum = 0;
  int i = 0;
  for (; i < num; i += 5) {
    sum += i;
  }
  return sum + i;
}
func.func @_Z3fooi(%arg0: i32) -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
  %c0 = arith.constant 0 : index
  %c5 = arith.constant 5 : index
  %c0_i32 = arith.constant 0 : i32
  %0 = arith.index_cast %arg0 : i32 to index
  %1 = scf.for %arg1 = %c0 to %0 step %c5 iter_args(%arg2 = %c0_i32) -> (i32) {
    %3 = arith.index_cast %arg1 : index to i32
    %4 = arith.addi %arg2, %3 : i32
    scf.yield %4 : i32
  }
  %2 = arith.addi %1, %arg0 : i32
  return %2 : i32
}

This instruction %2 = arith.addi %1, %arg0 : i32 is wrong because num is not necessarily a multiple of 5

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