[llvm] [InstSimplify] Provide information about the range of possible values that `ucmp`/`scmp` can return (PR #96410)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 23 00:41:18 PDT 2024


https://github.com/nikic commented:

In terms of high level approach, an alternative would be to instead add the `range(-1, 2)` return attribute to the intrinsic. This has the advantage that all places that understand range attributes will automatically gain support for this.

The downside is that doing this is not entirely straightforward. One could easily add the range to callsites in InstCombine, but it would be better to generate it directory on the declaration. That would be done by adding a new intrinsic property to https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/Intrinsics.td and then generating a call to the appropriate constructor in https://github.com/llvm/llvm-project/blob/e7622ab4721141d9e6af6041fa7f9bbc1029e9aa/llvm/utils/TableGen/IntrinsicEmitter.cpp#L420. The tricky thing is that in this case, while the range itself is fixed, the bit width of the range depends on the type overload, which is not the case for any of the existing intrinsic properties. So I think `Intrinsic::getAttributes()` would need an extra `FunctionType *` argument, so that the attributes for the correct type could be emitted.

https://github.com/llvm/llvm-project/pull/96410


More information about the llvm-commits mailing list