Uh oh!
There was an error while loading. Please reload this page.
Extend Equals/StartsWith auto-vectorization for OrdinalIgnoreCase - #66095
Conversation
ghost
commented
Mar 2, 2022
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsThis PR adds if the constant value contains at least one non-ASCII char (>127) - we give up on optimizing it. Codegen exampleboolEqualsCoreLib(strings)=>s.Equals("System.Private.CoreLib.dll",StringComparison.OrdinalIgnoreCase);New codegen: ; Method EqualsCoreLib(System.String):bool:thisG_M43376_IG01:vzeroupperG_M43376_IG02:cmp dword ptr [rdx+8],26jne SHORT G_M43376_IG04G_M43376_IG03:vmovupdymm0, ymmword ptr[rdx+12]vporymm0,ymm0, ymmword ptr[reloc @RWD00] ;; ToLowervpxorymm0,ymm0, ymmword ptr[reloc @RWD32]vmovupdymm1, ymmword ptr[rdx+32]vporymm1,ymm1, ymmword ptr[reloc @RWD64] ;; ToLowervpxorymm1,ymm1, ymmword ptr[reloc @RWD96]vporymm0,ymm0,ymm1vptestymm0,ymm0 sete almovzxrax,aljmp SHORT G_M43376_IG05G_M43376_IG04:xoreax,eaxG_M43376_IG05:movzxrax,alG_M43376_IG06:vzeroupperretRWD00 dq 0020002000200020h,0020000000200020h,0020002000200020h,0020000000200020hRWD32 dq 0074007300790073h,0070002E006D0065h,0061007600690072h,0063002E00650074hRWD64 dq 0020002000200020h,0020002000200000h,0020002000200020h,0020002000200000hRWD96 dq 0065007400610076h,0072006F0063002Eh,00620069006C0065h,006C006C0064002Eh; Total bytes of code: 77BenchmarkusingSystem;usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);publicclassBenchmarks{constStringComparisoncmp=StringComparison.OrdinalIgnoreCase;[Benchmark][Arguments("https://bing.com")]publicboolStartsWithBing(strings)=>s.StartsWith("https://bing",cmp);[Benchmark][Arguments("XMLFILE")]publicboolStartsWithXml(strings)=>s.StartsWith("xml",cmp);[Benchmark][Arguments("system.private.corelib.dll")]publicboolEqualsCoreLib(strings)=>s.Equals("System.Private.CoreLib.dll",cmp);}
10-20x faster for these cases. #65288 added tests which also cover
|
Uh oh!
There was an error while loading. Please reload this page.
EgorBo
commented
Mar 6, 2022
cc @dotnet/jit-contrib @AndyAyersMS |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| // We can use e.g. UINT here to support SIMD for 32bit as well, | ||
| // but it significantly complicates code, so 32bit support is left up-for-grabs | ||
| assert(sizeof(ssize_t) == 8); |
There was a problem hiding this comment.
You could use static_assert(...) here, so the code would never be enabled.
There was a problem hiding this comment.
good idea, will change in a follow up PR
| GenTree* xor1 = gtNewSimdBinOpNode(GT_XOR, simdType, vec1, cnsVec1, baseType, simdSize, false); | ||
| GenTree* xor2 = gtNewSimdBinOpNode(GT_XOR, simdType, vec2, cnsVec2, baseType, simdSize, false); | ||
| GenTree* orr = gtNewSimdBinOpNode(GT_OR, simdType, xor1, xor2, baseType, simdSize, false); | ||
| return gtNewSimdHWIntrinsicNode(TYP_BOOL, useSingleVector ? xor1 : orr, zero, niEquals, baseType, simdSize); |
There was a problem hiding this comment.
What happens when useSingleVector is true. xor2 and orr trees are just abandoned?
There was a problem hiding this comment.
Yes, but I assume it's a rare case, basically, 6.25% probability 😄 I was not sure it was worth it to add more control flow here or DEBUG_DESTROY
This PR adds
OrdinalIgnoreCasesupport to #65288 by injectingx | ToLowerMaskoperation where ToLowerMask looks like this for e.g for"ab1-C"constant value:if the constant value contains at least one non-ASCII char (>127) - we give up on optimizing it.
Codegen example
New codegen:
Benchmark
10-20x faster for these cases.
#65288 added tests which also cover
OrdinalIgnoreCasebut I might add more.jit-diff -f --crossgen
132 methods improved, I know that aspnetcore also uses it a lot.