From: Richard Biener Date: Thu, 24 Aug 2023 08:00:20 +0000 (+0200) Subject: tree-optimization/111128 - fix shift pattern recog X-Git-Tag: basepoints/gcc-15~6702 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b67cab154d4b5ec2a6bb62755da31cefbe63536;p=thirdparty%2Fgcc.git tree-optimization/111128 - fix shift pattern recog The following fixes placement of shift operand sanitization with MIN when the original shift operand was external but the actual one is not. PR tree-optimization/111128 * tree-vect-patterns.cc (vect_recog_over_widening_pattern): Emit external shift operand inline if we promoted it with another pattern stmt. * gcc.dg/torture/pr111128.c: New testcase. --- diff --git a/gcc/testsuite/gcc.dg/torture/pr111128.c b/gcc/testsuite/gcc.dg/torture/pr111128.c new file mode 100644 index 000000000000..aa623b0d0452 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr111128.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ + +int a, b, c, e, g; +short *d; +unsigned char f; +int h() { + f &= g; + for (; b; b++) { + a = 2; + for (; a; a--) + c = 0; + if (c) + continue; + e = (unsigned short)*d >> f; + } +} diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index cda27fed95bb..a2ed0365b18c 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -3121,7 +3121,7 @@ vect_recog_over_widening_pattern (vec_info *vinfo, = gimple_build_assign (new_var, MIN_EXPR, ops[1], build_int_cst (op_type, new_precision - 1)); gimple_set_location (pattern_stmt, gimple_location (last_stmt)); - if (unprom[1].dt == vect_external_def) + if (ops[1] == unprom[1].op && unprom[1].dt == vect_external_def) { if (edge e = vect_get_external_def_edge (vinfo, ops[1])) {