https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122845
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Last reconfirmed| |2025-11-25
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot
gnu.org
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This fixes this.
It also fixes PR 122843 because it removes the long chain in the first place.
```
diff --git a/gcc/match.pd b/gcc/match.pd
index 36d8f2f7275..ece5b2f4d01 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2317,13 +2317,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (GIMPLE
&& INTEGRAL_TYPE_P (type)
&& INTEGRAL_TYPE_P (TREE_TYPE (@0))
- && TREE_CODE (@1) != INTEGER_CST
&& tree_nop_conversion_p (type, TREE_TYPE (@2))
&& !POINTER_TYPE_P (TREE_TYPE (@0))
&& TREE_CODE (TREE_TYPE (@0)) != OFFSET_TYPE
&& TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (type))
- (bitop:type (convert @0) (convert @1)))))
-
+ (bitop:type (convert @0) (convert @1))
+ (if (GIMPLE
+ && INTEGRAL_TYPE_P (type)
+ && INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && types_match (type, TREE_TYPE (@0))
+ && TYPE_PRECISION (TREE_TYPE (@2)) > TYPE_PRECISION (type))
+ (bitop:type @0 (convert @1))))))
(for bitop (bit_and bit_ior)
rbitop (bit_ior bit_and)
/* (x | y) & x -> x */
```
I am still trying to understand the `TREE_CODE (@1) != INTEGER_CST` check that
is there for both cases above.
It also does not fix the unsigned case
where we have:
_3 = _2 ^ a_8(D);
_4 = _3 & 7;
_5 = _4 ^ a_8(D);
So maybe:
(simplify
(convert (bit_op:cs @0 (bit_and @1 INTEGER_CST@2)))
(if (TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0))
&& wi::to_wide (@2) == type_mask_inprecisionoftype (type, TREE_TYPE
(@0))))
(bit_op @0 (convert @1))