[llvm] [ValueTracking] Fix a bug for signed min-max clamping (PR #121206)

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 27 04:38:13 PST 2024


adam-bzowski wrote:

This fixes the bug present in PR 120576. The problem occurs when the min-max clamp returns *CLow and *CHigh being the minimum and maximum signed values respectively. In such a case *CHigh + 1 is the minimum signed value and the assertion in the constructor of ConstantRange fails. (Note that if *CHigh is the signed maximum but *CLow is strictly larger than the signed minimum, then ConstantRange is the correct range.)

I fixed the bug by checking for the problematic case. I also added some LIT tests and tweaked the previous ones. The altered tests use lshr now at the binary operator, which ensures that the min-max clamping is used in all cases. I also introduced some additional tests to test differences between sext and zext.

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


More information about the llvm-commits mailing list