]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
vect: drop prefetches during if-cvt [PR120164]
authorTamar Christina <tamar.christina@arm.com>
Wed, 27 May 2026 13:31:49 +0000 (14:31 +0100)
committerTamar Christina <tamar.christina@arm.com>
Wed, 27 May 2026 13:31:49 +0000 (14:31 +0100)
PR114061 added support for dropping prefetches during vectorization but that
version doesn't work when the prefetch is conditional.

The conditionality introduces a non-if-convertible block in the CFG.  The
vectorizer removes the prefetch later on but it can't modify the CFG and as
such the block where the prefetch was in remains with just a VUSEs chain.

This change now drops them during if-conversion.  While this patch at the moment
removes them, it makes it easier for later on, should we want to start
vectorizing these instead to just update predicate_statements.

For now this follows the same approach as PR114061 and just drops them.

gcc/ChangeLog:

PR tree-optimization/120164
* tree-if-conv.cc (if_convertible_stmt_p): Detect prefetches.
(predicate_statements): Drop them during predication.

gcc/testsuite/ChangeLog:

PR tree-optimization/120164
* gcc.dg/vect/vect-prefetch-drop_2.c: New test.

gcc/testsuite/gcc.dg/vect/vect-prefetch-drop_2.c [new file with mode: 0644]
gcc/tree-if-conv.cc

diff --git a/gcc/testsuite/gcc.dg/vect/vect-prefetch-drop_2.c b/gcc/testsuite/gcc.dg/vect/vect-prefetch-drop_2.c
new file mode 100644 (file)
index 0000000..3ac4eff
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_int } */
+
+void foo(int *restrict a, int *b, int n)
+{
+  for(int i=0; i<n; ++i){
+    a[i] = a[i] + b[i];
+    if (a[i] > 0)
+      __builtin_prefetch(&(b[i+8]));
+  }
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect"  } } */
+
index 218d2cb72386c5f6cc9906494589f90bef42b487..509b7ed4792a8860a5b1b08cebe30fdcaedd3b3c 100644 (file)
@@ -1202,6 +1202,12 @@ if_convertible_stmt_p (gimple *stmt, vec<data_reference_p> refs)
              }
          }
 
+       /* Check if it's a prefetch.  Many ISAs contain vectorized and/or
+          conditional prefetches so if-convert should convert them or remove
+          them.  Mark them as supported.  */
+       if (gimple_call_builtin_p (stmt, BUILT_IN_PREFETCH))
+         return true;
+
        /* There are some IFN_s that are used to replace builtins but have the
           same semantics.  Even if MASK_CALL cannot handle them vectorable_call
           will insert the proper selection, so do not block conversion.  */
@@ -3128,6 +3134,16 @@ predicate_statements (loop_p loop)
              release_defs (stmt);
              continue;
            }
+         /* For now, just drop prefetches.  Do it now to remove any possible
+            aliasing check failures from the address calculations of the
+            prefetch.  Vect would be too late in that regard.  */
+         else if (gimple_call_builtin_p (stmt, BUILT_IN_PREFETCH))
+           {
+             unlink_stmt_vdef (stmt);
+             gsi_remove (&gsi, true);
+             release_defs (stmt);
+             continue;
+           }
          else if (gimple_plf (stmt, GF_PLF_2)
                   && (is_gimple_assign (stmt)
                       || (gimple_call_builtin_p (stmt)