The following repro represents a suboptimal codegen for `IndexOfWhereAllBitsSet` that prevents me from using it: ```cs int idx = Vector128.IndexOfWhereAllBitsSet(cmp); if (idx != -1) { ... } ``` Minimal repro: ```cs static int IndexOf(int x) { int result = BitOperations.TrailingZeroCount(x); return (result != 32) ? result : -1; } static void Test(int x) { int idx = IndexOf(x); if (idx != -1) Console.WriteLine(idx); } ``` Actual codegen of `Test`: ```asm G_M44320_IG01: ;; offset=0x0000 G_M44320_IG02: ;; offset=0x0000 tzcnt ecx, ecx mov eax, -1 cmp ecx, 32 cmove ecx, eax cmp ecx, -1 jne SHORT G_M44320_IG04 G_M44320_IG03: ;; offset=0x0014 ret G_M44320_IG04: ;; offset=0x0015 tail.jmp [System.Console:WriteLine(int)] ``` Expected codegen of `Test`: ```asm G_M59698_IG01: ;; offset=0x0000 G_M59698_IG02: ;; offset=0x0000 tzcnt ecx, ecx cmp ecx, 32 jne SHORT G_M59698_IG04 G_M59698_IG03: ;; offset=0x0009 ret G_M59698_IG04: ;; offset=0x000A tail.jmp [System.Console:WriteLine(int)] ``` so effectively jit should lower it to: ```cs static void Test(int x) { int idx = BitOperations.TrailingZeroCount(x); if (idx != 32) { Console.WriteLine(idx); } } ```
Activity
EgorBo commentedon Apr 9, 2026
cc @AndyAyersMS
dotnet-policy-service commentedon Apr 9, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
Copilot's fix for dotnet#126703
EgorBo commentedon Apr 9, 2026
Copilot's suggestion: https://github.com/dotnet/runtime/compare/main...EgorBo:rbo-fix?expand=1
(seems to generate quite a few diffs)
JIT: refine SSA info in ambiguously threaded blocks
JIT: refine SSA info in ambiguously threaded blocks (#126907)
JIT: refine SSA info in ambiguously threaded blocks (#126907)