dotnet / dotnet/fsharp

Optimization issues with inlined il + generated IL

Open
#9,753 1 comment 0 reactions 0 assignees View on GitHub
Area-Compiler-Optimization Feature Request
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

While working on this PR: https://github.com/dotnet/fsharp/pull/9715

@abelbraaksma identified optimization issues when combining inline il with other generated code

https://github.com/dotnet/fsharp/pull/9715

@KevinRansom, @cartermp, When working with this fix I noticed some other cases where incorrect boolean optimizations are done. I'm still analyzing that, but this fix produces better IL for the majority of cases.

The optimizer is split in optimizing inline IL and normal code. When it is mixed, esp wrt booleans, it goes wrong and dead IL code is created. What's worse, when combined with null checks, the code didn't eliminate the `not`, but created code that was many times slower.

This simple fix takes care of all that. Yes, there are now other cases, but the way this fix was done ensures that the new cases are very limited, and that existing optimizations with comparison operators continue to work.

I intend to investigate further for optimizations of boolean expressions, esp boolean negation. But that should go in its own issue. I'll report that separately, as it's a much wider issue than this one (and may end up being wip for some time).

_Originally posted by @abelbraaksma in https://github.com/dotnet/fsharp/pull/9715#issuecomment-662087154_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.