The slice len/cap are known to be in the range [0, (^uintptr(0) >> 1) / elemSize].
We should provide this information to LLVM because:
- It can prove that index math (like
x + y / 2) will not overflow
- We sometimes mix signed and unsigned comparisons, which can confuse the compiler.
In order to do this, we must:
- Wrap
LLVMCreateConstantRangeAttribute in our bindings
- Attach the range metadata to the function parameters
- Attach the range metadata to slicing operations
Unfortunately, LLVMCreateConstantRangeAttribute was not introduced until LLVM 19.1. We may need to condition the logic on LLVM version.