https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103194
--- Comment #10 from Hongtao.liu <crazylht at gmail dot com> --- (In reply to Hongtao.liu from comment #9) > (In reply to H.J. Lu from comment #6) > > Created attachment 51785 [details] > > The v2 incomplete patch > > > > Hongtao, please finish it. Thanks. > > I'm trying to handle narrowing part in match.pd and add else return; when > precision is not equal. > > (for bit_op (bit_and bit_xor bit_ior) > (simplify > (bit_op (convert@0 @1) (convert@2 @3)) > (if (INTEGRAL_TYPE_P (type) > && INTEGRAL_TYPE_P (TREE_TYPE (@1)) > && tree_nop_conversion_p (TREE_TYPE (@1), TREE_TYPE (@3)) > && single_use (@0) > && single_use (@2) > && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@1))) > (with { tree type1 = TREE_TYPE (@1); } > (convert (bit_op @1 (convert:type1 @3))))))) > > (for bit_op (bit_and bit_xor bit_ior) > (simplify > (bit_op (convert@0 @1) INTEGER_CST@2) > (if (INTEGRAL_TYPE_P (type) > && INTEGRAL_TYPE_P (TREE_TYPE (@1)) > && single_use (@0) > && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@1))) > (convert (bit_op @1 { fold_convert (TREE_TYPE (@1), @2); }))))) hmm, cause infinite loop because of /* Convert (T)(x & c) into (T)x & (T)c, if c is an integer constants (if x has signed type, the sign bit cannot be set in c). This folds extension into the BIT_AND_EXPR. ??? We don't do it for BOOLEAN_TYPE or ENUMERAL_TYPE because they very likely don't have maximal range for their precision and this transformation effectively doesn't preserve non-maximal ranges. */ if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (op0) == BIT_AND_EXPR && TREE_CODE (TREE_OPERAND (op0, 1)) == INTEGER_CST)