JIT: CSE doesn't consider two comparisons with swapped operands equal
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 54/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- csharp
- Domain
- performance
Research direction
Start with the JIT common subexpression elimination logic and its tests; the issue does not name specific files or test entry points. Compare how the JIT represents a < b and b > a, then check whether equivalent comparisons are reused. Done means the swapped-operand case produces one comparison, with a regression test covering both forms.
Written by the indexing model from the issue text.
Description
https://godbolt.org/z/TffET5sK4
Consider:
static void Good(int a, int b, bool* mem)
{
// Successfully CSE'd!
mem[0] = a < b;
mem[1] = a < b;
}
Program:Good(int,int,ptr) (FullOpts):
cmp edi, esi
setl al
movzx eax, al
mov byte ptr [rdx], al
mov byte ptr [rdx+0x01], al
ret
Now, let's swap the operands. CSE no longer recognizes them as equal.
static void Failed(int a, int b, bool* mem)
{
mem[0] = a < b;
mem[1] = b > a;
}
Program:Failed(int,int,ptr) (FullOpts):
cmp edi, esi
setl al
mov byte ptr [rdx], al
cmp esi, edi
setg al
mov byte ptr [rdx+0x01], al
ret
- Dominant language
- C#
- Stars
- 18.5k
- Forks
- 5.8k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 588
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
area-CodeGen-coreclr untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
dotnet/runtime#138181 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Collections untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
dotnet/runtime#138090 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Text.Json untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dotnet/runtime#138089 · 1 comment ·
Maintainers usually reply within 1 day
-
area-Setup untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
dotnet/runtime#137376 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Memory untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
dotnet/runtime#137334 · 4 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Add `net10.0`Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
dotnet-outdated/dotnet-outdated#871 ·
Maintainers usually reply within 1 day
-
triage/untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
unoplatform/uno#26676 ·
Maintainers usually reply within 1 day
-
.NET bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
jhaizhou-ops/S2Arm#2177 · 3 comments ·
Maintainers usually reply within 1 day