]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PR tree-optimization/107052] range-ops: Pass nonzero masks through cast.
authorAldy Hernandez <aldyh@redhat.com>
Tue, 4 Oct 2022 15:03:54 +0000 (17:03 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Wed, 5 Oct 2022 12:21:01 +0000 (14:21 +0200)
Track nonzero masks through a cast in range-ops.

PR tree-optimization/107052

gcc/ChangeLog:

* range-op.cc (operator_cast::fold_range): Set nonzero mask.

gcc/range-op.cc

index 4f647abd91c1ebc481a8256336a5fd7b48be0c39..6fa27a8904e8f8be1617c3dd83c2c80bf94fbb3c 100644 (file)
@@ -2515,6 +2515,14 @@ operator_cast::fold_range (irange &r, tree type ATTRIBUTE_UNUSED,
       if (r.varying_p ())
        return true;
     }
+
+  // Pass nonzero mask through the cast.
+  if (!truncating_cast_p (inner, outer))
+    {
+      wide_int nz = inner.get_nonzero_bits ();
+      nz = wide_int::from (nz, TYPE_PRECISION (type), TYPE_SIGN (inner.type ()));
+      r.set_nonzero_bits (nz);
+    }
   return true;
 }