]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/111128 - fix shift pattern recog
authorRichard Biener <rguenther@suse.de>
Thu, 24 Aug 2023 08:00:20 +0000 (10:00 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 24 Aug 2023 08:59:16 +0000 (10:59 +0200)
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.

gcc/testsuite/gcc.dg/torture/pr111128.c [new file with mode: 0644]
gcc/tree-vect-patterns.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr111128.c b/gcc/testsuite/gcc.dg/torture/pr111128.c
new file mode 100644 (file)
index 0000000..aa623b0
--- /dev/null
@@ -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;
+  }
+}
index cda27fed95bba965a8700dda114fa3e0d2fe1366..a2ed0365b18cce927e4ebca5d4c15abd820355d3 100644 (file)
@@ -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]))
                {