Description of the project: 3-way comparisons return the values -1, 0 or 1 depending on whether the values compare lower, equal or greater. They are exposed in C++ via the spaceship operator (operator<=>
) and in Rust via the PartialOrd
and Ord
traits. Currently, such comparisons produce sub-optimal codegen and optimization results in some cases.
The goal of this project is to resolve these optimization issues by implementing new 3-way comparison intrinsics, as described in [RFC] Add 3-way comparison intrinsics. The implementation steps are broadly:
- Add the intrinsics to LLVM IR.
- Implement legalization/expansion support in SelectionDAG and GlobalISel.
- Implement optimization support in ConstantFolding, InstSimplify, InstCombine, CorrelatedValuePropagation, IndVarSimplify, ConstraintElimination, IPSCCP, and other relevant transforms.
- Make use of the intrinsics via InstCombine canonicalization or direct emission in clang/rustc.
Adding new target-independent intrinsics is a good way of becoming familiar with a broad slice of LLVM!
Expected results: Support for the intrinsics in the backend and the most important optimization passes. Ideally full integration starting at the frontend.
Desirable skills: Intermediate C++
Project size: Medium or large
Difficulty: Medium