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

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 27 06:15:33 PST 2024


================
@@ -1119,7 +1119,8 @@ static void unionWithMinMaxIntrinsicClamp(const IntrinsicInst *II,
                                           KnownBits &Known) {
   const APInt *CLow, *CHigh;
   if (isSignedMinMaxIntrinsicClamp(II, CLow, CHigh))
-    Known = Known.unionWith(ConstantRange(*CLow, *CHigh + 1).toKnownBits());
+    if (!(CLow->isMinSignedValue() && CHigh->isMaxSignedValue()))
----------------
topperc wrote:

Instead of this check, you can use `ConstantRange::getNonEmpty` instead of the `ConstantRange` constructor. `getNonEmpty` will convert the range to a valid full set when Lower and Upper are equal.

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


More information about the llvm-commits mailing list