dotnet / dotnet/runtime

JIT: Combine before OR in `OptimizeBools`

Open
#125,585 1 comment 0 reactions 0 assignees View on GitHub
area-CodeGen-coreclr
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

A case from https://devblogs.microsoft.com/cppblog/c-performance-improvements-in-msvc-build-tools-v14-51/#ternary-operator-optimization.

https://godbolt.org/z/bvc7Gaq9G
```cs
void TernaryOperator(uint x, uint y)
{
// Expected:
// if ((x | y) < 0x10000u)
// or edi, esi
// cmp edi, 65536
// jae void bar(void)

uint a = x < 0x10000u ? 0u : 1u;
uint b = y < 0x10000u ? 0u : 1u;

if ((a | b) != 0) {
Consume(0);
}
}
```
Currently is after `OptimizeBools`:
```markdown
[000015] -----+----- * JTRUE void $VN.Void
[000014] J----+-N--- \--* EQ int $103
[000012] -----+----- +--* OR int $102
[000002] N----+---U- | +--* GE int $100
[000000] -----+----- | | +--* LCL_VAR int V01 arg1 u:1 (last use) $80
[000001] -----+----- | | \--* CNS_INT int 0x10000 $43
[000007] N----+---U- | \--* GE int $101
[000005] -----+----- | +--* LCL_VAR int V02 arg2 u:1 (last use) $81
[000006] -----+----- | \--* CNS_INT int 0x10000 $43
[000013] -----+----- \--* CNS_INT int 0 $44
```
Could be:
```markdown
[000005] -----+----- * JTRUE void $VN.Void
[000004] N----+-N-U- \--* GE int $101
[000002] -----+----- +--* OR int $100
[000000] -----+----- | +--* LCL_VAR int V01 arg1 u:1 (last use) $80
[000001] -----+----- | \--* LCL_VAR int V02 arg2 u:1 (last use) $81
[000003] -----+----- \--* CNS_INT int 0x10000 $44
```

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.