* [COMMITTED] range-op: Keep nonzero mask up to date with truncating casts.
@ 2022-10-05 13:49 Aldy Hernandez
0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2022-10-05 13:49 UTC (permalink / raw)
To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez
gcc/ChangeLog:
* range-op.cc (operator_cast::fold_range): Handle truncating casts
for nonzero masks.
---
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;
}
--
2.37.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-10-05 13:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-05 13:49 [COMMITTED] range-op: Keep nonzero mask up to date with truncating casts Aldy Hernandez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).