From: Aldy Hernandez Date: Tue, 4 Oct 2022 15:03:54 +0000 (+0200) Subject: [PR tree-optimization/107052] range-ops: Pass nonzero masks through cast. X-Git-Tag: basepoints/gcc-14~4122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae56d600d223e996054483d7d7033ec8e258d39d;p=thirdparty%2Fgcc.git [PR tree-optimization/107052] range-ops: Pass nonzero masks through cast. 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. --- diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 4f647abd91c1..6fa27a8904e8 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -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; }