Jit: Missing folding some compares in optimizebools
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
Code like the following (from [this test](https://github.com/dotnet/runtime/blob/1492e43b14755a0360e379f1a5a30b5c59cc51e4/src/tests/JIT/opt/OptimizeBools/optboolsreturn.cs#L242)) should have the eq and gt folded into GE:
```
private static bool IsGreaterThanOrEqualZero(int x)
{
bool b = x == 0 || x > 0;
if (b)
{
Console.WriteLine("IsGreaterThanOrEqualZero true");
}
return b;
}
```
I looked at arm64 and x64 targets, and we still generate a redundant test instruction(*)
```
IN0001: 000005 mov ebx, 1
IN0002: 00000A test ecx, ecx
IN0003: 00000C setg al
IN0004: 00000F movzx rax, al
IN0005: 000012 test ecx, ecx *
IN0006: 000014 cmovne ebx, eax
IN0007: 000017 test ebx, ebx
IN0008: 000019 je SHORT G_M32186_IG04
```
I think optimizebools was supposed to get this via [this pr](https://github.com/dotnet/runtime/pull/78786) but perhaps got regressed over a couple years.
category:cq
theme:basic-cq
skill-level:beginner
cost:small
impact:small
Contributor guide
Assessment
This issue has not been assessed yet.