Micha Reiser via llvm-dev
2017-Apr-24 10:34 UTC
[llvm-dev] 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 -------------- 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>
Craig Topper via llvm-dev
2017-Apr-24 15:11 UTC
[llvm-dev] Disable if with store to select optimization pass
If its the conversion I know of, try -simplifycfg-merge-cond-stores=false ~Craig On Mon, Apr 24, 2017 at 3:34 AM, Micha Reiser via llvm-dev < llvm-dev at lists.llvm.org> wrote:> 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 > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170424/dc2d997d/attachment-0001.html>