llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
327 stars 86 forks source link

[CIR] Lower certain `cir.cmp3way` operations to LLVM intrinsics #556

Closed Lancern closed 3 months ago

Lancern commented 3 months ago

LLVM recently added two families of intrinsics named llvm.scmp.* and llvm.ucmp.* that generate potentially better code for three-way comparison operations. This PR lowers certain cir.cmp3way operations to these intrinsics.

Not all cir.cmp3way operations can be lowered to these intrinsics. The qualifying conditions are: 1) the comparison is between two integers, and 2) the comparison produces a strong ordering. cir.cmp3way operations that are not qualified are not affected by this PR.

Qualifying cir.cmp3way operations may still need some canonicalization work before lowering. The "canonicalized" form of a qualifying three-way comparison operation yields -1 for lt, 0 for eq, and 1 for gt. This PR converts those non-canonicalized but qualifying cir.cmp3way operations to their canonical forms in the LLVM lowering prepare pass.

This PR addresses #514 .