diff --git a/gcc/match.pd b/gcc/match.pd index 48317dc80b63ee42694b0027a976bbc6d8aac0b3..ad354274b2a1992e2094489d28c28dfe339f13b8 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4933,7 +4933,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) #if GIMPLE /* (X >> C1) << (C1 + C2) -> X << C2 if the low C1 bits of X are zero. */ (simplify - (lshift (convert? (rshift (with_possible_nonzero_bits2 @0) INTEGER_CST@1)) + (lshift (convert? (rshift with_possible_nonzero_bits@0 INTEGER_CST@1)) INTEGER_CST@2) (if (INTEGRAL_TYPE_P (type) && wi::ltu_p (wi::to_wide (@1), element_precision (type)) @@ -4944,7 +4944,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (X >> C1) * (C2 << C1) -> X * C2 if the low C1 bits of X are zero. */ (simplify - (mult (convert? (rshift (with_possible_nonzero_bits2 @0) INTEGER_CST@1)) + (mult (convert? (rshift with_possible_nonzero_bits@0 INTEGER_CST@1)) poly_int_tree_p@2) (with { poly_widest_int factor; } (if (INTEGRAL_TYPE_P (type) @@ -5519,7 +5519,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) #if GIMPLE /* X / (1 << C) -> X /[ex] (1 << C) if the low C bits of X are clear. */ (simplify - (trunc_div (with_possible_nonzero_bits2 @0) integer_pow2p@1) + (trunc_div with_possible_nonzero_bits@0 integer_pow2p@1) (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type) && wi::multiple_of_p (get_nonzero_bits (@0), wi::to_wide (@1), SIGNED)) diff --git a/gcc/testsuite/gcc.dg/torture/pr117420.c b/gcc/testsuite/gcc.dg/torture/pr117420.c new file mode 100644 index 0000000000000000000000000000000000000000..854768e61d3ea866d03eaf1153b5fc5acc1f7b6f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr117420.c @@ -0,0 +1,52 @@ +/* PR tree-optimization/117420 */ +/* { dg-do run } */ + +int a; + +__attribute__((noipa)) int +foo () +{ + int b = -(1 | -(a < 1)); + int c = (~b & 2) / 2; + if (b != 1) + __builtin_abort (); +} + +__attribute__((noipa)) int +bar () +{ + int b = -(1 | -(a < 1)); + int c = (~b & 2) / 2; + if (b != -1) + __builtin_abort (); +} + +__attribute__((noipa)) int +baz () +{ + int b = -(1 | -(a < 1)); + int c = (~b & 2) / 2; + if (c != 1) + __builtin_abort (); +} + +__attribute__((noipa)) int +qux () +{ + int b = -(1 | -(a < 1)); + int c = (~b & 2) / 2; + if (c != 0) + __builtin_abort (); +} + +int +main () +{ + foo (); + a = 1; + bar (); + a = 0; + baz (); + a = 1; + qux (); +}