[gcc r16-6973] tree-optimization/123755 - properly register loop mask for trapping call

Richard Biener rguenth@gcc.gnu.org
Thu Jan 22 12:02:11 GMT 2026


https://gcc.gnu.org/g:2c2a07e31cdb9bdb7b84d996afd71d9976326b1f

commit r16-6973-g2c2a07e31cdb9bdb7b84d996afd71d9976326b1f
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jan 22 11:22:15 2026 +0100

    tree-optimization/123755 - properly register loop mask for trapping call
    
    The following makes sure to register a loop mask if we mask the loop
    because the call could trap.
    
            PR tree-optimization/123755
            * tree-vect-stmts.cc (vectorizable_call): Register mask when
            the call could trap.
    
            * gcc.dg/vect/vect-pr123755.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/vect-pr123755.c | 12 ++++++++++++
 gcc/tree-vect-stmts.cc                    |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr123755.c b/gcc/testsuite/gcc.dg/vect/vect-pr123755.c
new file mode 100644
index 000000000000..888efb967e2b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-pr123755.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+float a[4], b[4];
+
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 4; ++i)
+    b[i] = __builtin_fma (1024.0f, 1024.0f, a[i]);
+  return 0;
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 83983742467c..5fc115e1a179 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -3721,7 +3721,7 @@ vectorizable_call (vec_info *vinfo,
 
       if (loop_vinfo
 	  && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
-	  && (reduc_idx >= 0 || mask_opno >= 0))
+	  && (reduc_idx >= 0 || could_trap || mask_opno >= 0))
 	{
 	  if (reduc_idx >= 0
 	      && (cond_fn == IFN_LAST


More information about the Gcc-cvs mailing list