The following makes sure to register a loop mask if we mask the loop
because the call could trap.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
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.
---
gcc/testsuite/gcc.dg/vect/vect-pr123755.c | 12 ++++++++++++
gcc/tree-vect-stmts.cc | 2 +-
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-pr123755.c
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 00000000000..888efb967e2
--- /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 113cd315295..3b8f0075544 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
--
2.51.0