Disable if with store to select optimization pass

Hy everyone

I'm writing an LLVM frontend that compiles a subset of TypeScript to WebAssembly using the new experimental Web Assembly Target. and LLVM opt to optimize the output. As part of my work, I compare the runtime of the generated Web Assembly implementation to the plain JavaScript version. During this evaluation, I noticed that LLVM opt converts if statements with a store to a select statement to reduce the number of branches. E.g., the following

for (let j = i; j < points.length; j += 2) {
  const distance = euclideanDistance(currentX, currentY, points[j], points[j+1]);

  if (distance < shortestDistance) {
    shortestDistance = distance;
    nearestIndex = j;
  }
}

collapses to (the if is removed)

for (let j = i; j < points.length; j += 2) {
  const distance = euclideanDistance(currentX, currentY, points[j], points[j+1]);

  let shorter = distance < shortestDistance;
  shortestDistance shorter ? distance : shortestDistance;
  nearestIndex = shorter ? j : nearestIndex;
}

My benchmarks show that this optimization has a negative impact on performance (at least if there are two or more assignments). Therefore, I would like to disable this optimization pass or at least tune it only to collapse the if statement if there is only a single assignment.

Is there a way to disable this optimization pass or fine tune it to define how many statements are allowed to be collapsed?

Thank you very much,
Micha

If its the conversion I know of, try -simplifycfg-merge-cond-stores=false