[llvm-dev] Disable if with store to select optimization pass

Micha Reiser via llvm-dev llvm-dev at lists.llvm.org
Mon Apr 24 03:34:07 PDT 2017


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170424/49c6a7fc/attachment.sig>


More information about the llvm-dev mailing list