From 11a86c5688cfcf22c52cf737070a8d3df5a59285 Mon Sep 17 00:00:00 2001 From: "Charles M. Hannum" Date: Fri, 26 Mar 1999 15:46:33 -0700 Subject: [PATCH] fold-const.c (fold_truthop): Optimize bitfield references with different masks as long as their size and bit... * fold-const.c (fold_truthop): Optimize bitfield references with different masks as long as their size and bit position are the same. From-SVN: r26006 --- gcc/ChangeLog | 3 +++ gcc/fold-const.c | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8822a94d096..f14f7df682d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -65,6 +65,9 @@ Fri Mar 26 10:43:47 1999 Nick Clifton Fri Mar 26 01:59:15 1999 "Charles M. Hannum" + * fold-const.c (fold_truthop): Optimize bitfield references with + different masks as long as their size and bit position are the same. + * fold-const.c (fold_truthop): Build a type for both the lhs and rhs and use it appropriately. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index d96aa3c8279..9b003c2ec22 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -3934,25 +3934,24 @@ fold_truthop (code, truth_type, lhs, rhs) size_int (xrr_bitpos), 0); /* Make a mask that corresponds to both fields being compared. - Do this for both items being compared. If the masks agree, - and the bits being compared are in the same position, and the - types agree, then we can do this by masking both and comparing - the masked results. */ + Do this for both items being compared. If the operands are the + same size and the bits being compared are in the same position + then we can do this by masking both and comparing the masked + results. */ ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0); lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask, 0); - if (operand_equal_p (ll_mask, lr_mask, 0) - && lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos - && lntype == rntype) + if (lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos) { lhs = make_bit_field_ref (ll_inner, lntype, lnbitsize, lnbitpos, ll_unsignedp || rl_unsignedp); + if (! all_ones_mask_p (ll_mask, lnbitsize)) + lhs = build (BIT_AND_EXPR, lntype, lhs, ll_mask); + rhs = make_bit_field_ref (lr_inner, rntype, rnbitsize, rnbitpos, lr_unsignedp || rr_unsignedp); - if (! all_ones_mask_p (ll_mask, lnbitsize)) - { - lhs = build (BIT_AND_EXPR, lntype, lhs, ll_mask); - rhs = build (BIT_AND_EXPR, rntype, rhs, ll_mask); - } + if (! all_ones_mask_p (lr_mask, rnbitsize)) + rhs = build (BIT_AND_EXPR, rntype, rhs, lr_mask); + return build (wanted_code, truth_type, lhs, rhs); } -- 2.30.2