Skip to content

GCM may hoist "division by zero" above the guarding "if" #240

@dstogov

Description

@dstogov

In the following code, GCM hoists x / y out of the loop.
This causes division by zero even if value of n is zero.

val test = {i32 n, i32 x, i32 y ->
  i32 z = 0;
  i32 i = 0;
  while (i < n) {
    z = x / y;
    i = i + 1;
  }
  return z;
};

Probably, nodes with possible side effect should be linked into the control chain.
It seems C2 does this, but this is too pessimistic decision that limits possible optimizations.

May be you though about some better solution?

(I have exactly the same problem in my project).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions