From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id D7ED4385801A; Wed, 5 Oct 2022 13:49:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7ED4385801A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664977785; bh=3s0jV5cV26L4XXwAgNTBRNvg+S4lWoNq52873YFLA9k=; h=From:To:Subject:Date:From; b=ShSmSVyHxmZvVZOu2/P+F8Ld5Rwu6KO0vwWYg5bZFXuyvChxUzOCPUiaTqlHm1xry 3ZaHl5hcbQ3XI8h5iSSyFXrjyzsuoFitP992wqa9Dx5IXrg2hIlNB+/KxENYSxmbXd QY5pFX6h30Lxm/Gs1WYxR2iI8oLPn/yjYwSJJ3KI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3090] range-op: Keep nonzero mask up to date with truncating casts. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: b8473c9a2b8f27b6882b54d012e466e244445733 X-Git-Newrev: df4c584c567263fdcd57d8376f24f29477a892b2 Message-Id: <20221005134945.D7ED4385801A@sourceware.org> Date: Wed, 5 Oct 2022 13:49:45 +0000 (GMT) List-Id: https://gcc.gnu.org/g:df4c584c567263fdcd57d8376f24f29477a892b2 commit r13-3090-gdf4c584c567263fdcd57d8376f24f29477a892b2 Author: Aldy Hernandez Date: Wed Oct 5 13:24:49 2022 +0200 range-op: Keep nonzero mask up to date with truncating casts. gcc/ChangeLog: * range-op.cc (operator_cast::fold_range): Handle truncating casts for nonzero masks. Diff: --- gcc/range-op.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 6fa27a8904e..df0735cb42a 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -2516,13 +2516,17 @@ operator_cast::fold_range (irange &r, tree type ATTRIBUTE_UNUSED, 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); - } + // Update the nonzero mask. Truncating casts are problematic unless + // the conversion fits in the resulting outer type. + wide_int nz = inner.get_nonzero_bits (); + if (truncating_cast_p (inner, outer) + && wi::rshift (nz, wi::uhwi (TYPE_PRECISION (outer.type ()), + TYPE_PRECISION (inner.type ())), + TYPE_SIGN (inner.type ())) != 0) + return true; + nz = wide_int::from (nz, TYPE_PRECISION (type), TYPE_SIGN (inner.type ())); + r.set_nonzero_bits (nz); + return true; }