The following fixes up r13-469-g9a53101caadae1b5 by properly implementing what operand_equal_for_comparison_p did.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2022-06-24 Richard Biener <rguent...@suse.de> PR middle-end/106070 * match.pd (a != b ? a : b): Fix translation of operand_equal_for_comparison_p. * gcc.dg/torture/pr106070.c: New testcase. --- gcc/match.pd | 11 +++++++---- gcc/testsuite/gcc.dg/torture/pr106070.c | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr106070.c diff --git a/gcc/match.pd b/gcc/match.pd index 4a570894b2e..e486b4be282 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4574,12 +4574,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cond (cmp:c (nop_convert1?@c0 @0) (nop_convert2?@c1 @1)) (convert3? @0) (convert4? @1)) (if (!HONOR_SIGNED_ZEROS (type) - && ((INTEGRAL_TYPE_P (type) - /* Allow widening conversions of the data. */ + && (/* Allow widening conversions of the compare operands as data. */ + (INTEGRAL_TYPE_P (type) + && types_match (TREE_TYPE (@c0), TREE_TYPE (@0)) + && types_match (TREE_TYPE (@c1), TREE_TYPE (@1)) && TYPE_PRECISION (TREE_TYPE (@0)) <= TYPE_PRECISION (type) && TYPE_PRECISION (TREE_TYPE (@1)) <= TYPE_PRECISION (type)) - || (tree_nop_conversion_p (type, TREE_TYPE (@0)) - && tree_nop_conversion_p (type, TREE_TYPE (@1))))) + /* Or sign conversions for the comparison. */ + || (types_match (type, TREE_TYPE (@0)) + && types_match (type, TREE_TYPE (@1))))) (switch (if (cmp == EQ_EXPR) (if (VECTOR_TYPE_P (type)) diff --git a/gcc/testsuite/gcc.dg/torture/pr106070.c b/gcc/testsuite/gcc.dg/torture/pr106070.c new file mode 100644 index 00000000000..c36534f8a50 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr106070.c @@ -0,0 +1,20 @@ +/* { dg-do run } */ + +unsigned int var_2 = 1; +int var_4 = -1; +int var_10 = 4; +unsigned long arr_252; +void __attribute__((noipa)) test() { + for (int a = 0; a < var_10; a += 2) + arr_252 = var_2 != (int)var_4 ? (unsigned long)var_4 : (unsigned long)var_2; +} + +void test(); + +int main() +{ + test(); + if (arr_252 != 0xffffffffffffffff) + __builtin_abort(); + return 0; +} -- 2.35.3