Skip to content

CPU backend disagrees with plain JavaScript on three control-flow shapes #865

Description

@fuzzie360

Found by adversarial review while verifying the WebAssembly backend (feature/webasm-backend), which matches plain JS on all three where cpu does not. All three are pre-existing on develop and unrelated to that branch.

1. Early return inside a loop returns the post-loop value for every cell.

gpu.createKernel(function () {
  for (let i = 0; i < 20; i++) {
    if (i * i > this.thread.x) { return i * 100 + this.thread.x; }
  }
  return -1;
}, { output: [6] });
// cpu:      [-1, -1, -1, -1, -1, -1]
// plain JS: [100, 201, 202, 203, 304, 305]   (webasm agrees)

The translated loop keeps running after the return.

2. Do-while with continue does not jump to the test correctly — a do/while accumulating with if (i % 3 === 0) continue; returns 56 on cpu where plain JS gives 45.

3. Assignment to a scalar argument leaks across cellsbase = base + this.thread.x; return base; with base = 10 returns [10, 11, 13, 16, ...] on cpu (the mutation accumulates across the cell loop) where per-cell JS, the GL backends and webasm give [10, 11, 12, 13].

The webasm suite pins these shapes against per-cell plain-JS references (test/features/webasm/control-flow.js) precisely because the cpu backend cannot serve as ground truth for them. Fixing cpu should add the same three shapes to a cpu regression file.

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