diff options
author | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1999-03-26 21:52:14 +0000 |
---|---|---|
committer | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1999-03-26 21:52:14 +0000 |
commit | 4cf66b974e6afeea0c30f77be2b391dc3d77e049 (patch) | |
tree | 78a476e1fb06efb51cbc4e1ab6e07cdd1af05727 /gcc/fold-const.c | |
parent | d989b2599a8dd29099d2953be4883de362636943 (diff) | |
download | gcc-4cf66b974e6afeea0c30f77be2b391dc3d77e049.tar.gz |
* fold-const.c (fold_truthop): Mask the lhs and rhs after merging
adjacent bitfield references.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@26004 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 78d7e41f8e3..93a0ae06ba9 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -3956,20 +3956,32 @@ fold_truthop (code, truth_type, lhs, rhs) /* There is still another way we can do something: If both pairs of fields being compared are adjacent, we may be able to make a wider - field containing them both. */ + field containing them both. + + Note that we still must mask the lhs/rhs expressions. Furthermore, + the mask must be shifted to account for the shift done by + make_bit_field_ref. */ if ((ll_bitsize + ll_bitpos == rl_bitpos && lr_bitsize + lr_bitpos == rr_bitpos) || (ll_bitpos == rl_bitpos + rl_bitsize && lr_bitpos == rr_bitpos + rr_bitsize)) - return build (wanted_code, truth_type, - make_bit_field_ref (ll_inner, type, - ll_bitsize + rl_bitsize, - MIN (ll_bitpos, rl_bitpos), - ll_unsignedp), - make_bit_field_ref (lr_inner, type, - lr_bitsize + rr_bitsize, - MIN (lr_bitpos, rr_bitpos), - lr_unsignedp)); + { + lhs = make_bit_field_ref (ll_inner, type, ll_bitsize + rl_bitsize, + MIN (ll_bitpos, rl_bitpos), ll_unsignedp); + ll_mask = const_binop (RSHIFT_EXPR, ll_mask, + size_int (MIN (xll_bitpos, xrl_bitpos)), 0); + if (! all_ones_mask_p (ll_mask, ll_bitsize + rl_bitsize)) + lhs = build (BIT_AND_EXPR, type, lhs, ll_mask); + + rhs = make_bit_field_ref (lr_inner, type, lr_bitsize + rr_bitsize, + MIN (lr_bitpos, rr_bitpos), lr_unsignedp); + lr_mask = const_binop (RSHIFT_EXPR, lr_mask, + size_int (MIN (xlr_bitpos, xrr_bitpos)), 0); + if (! all_ones_mask_p (lr_mask, lr_bitsize + rr_bitsize)) + rhs = build (BIT_AND_EXPR, type, rhs, lr_mask); + + return build (wanted_code, truth_type, lhs, rhs); + } return 0; } |