Skip to content

Made Equality Tests Smarter#38

Merged
nlordell merged 1 commit into
nlordell:mainfrom
NCGThompson:equality-hint
Apr 16, 2025
Merged

Made Equality Tests Smarter#38
nlordell merged 1 commit into
nlordell:mainfrom
NCGThompson:equality-hint

Conversation

@NCGThompson

Copy link
Copy Markdown
Contributor

Currently, == compares the underlying arrays. This compiles to memcmp in llvm. memcmp is then optimized to bcmp. The problem with this is that llvm-opt doesn't do much with bcmp during the instcombine pass. It will also sometimes write to memory just to read it back again.

What I did to work around this in div-rem was use unreachable_unchecked() calls to tell the compiler that the bcmp is equivalent to two icmps. I have considered overloading the == operator with a bcmp plus hints, but now I believe it is best to not use bcmp at all. Ethnum's integers have public fields, so the current equality operation can always be called with a.0 == b.0.

I compared and annotated a few alternatives on Compiler Explorer. Note that I have not considered adding an llvm intrinsic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants