diff mbox series

[v3,3/8] tree-ifcvt: Enforce zero else value after maskload.

Message ID 20241031153353.51254-4-rdapp.gcc@gmail.com
State New
Headers show
Series Add maskload else operand. | expand

Commit Message

Robin Dapp Oct. 31, 2024, 3:33 p.m. UTC
From: Robin Dapp <rdapp@ventanamicro.com>

When predicating a load we implicitly assume that the else value is
zero.  This matters in case the loaded value is padded (like e.g.
a Bool) and we must ensure that the padding bytes are zero on targets
that don't implicitly zero inactive elements.

A former version of this patch still had this handling in ifcvt but
the latest version defers it to the vectorizer.

gcc/ChangeLog:

	* tree-if-conv.cc (predicate_load_or_store): Add zero else
	operand and comment.
---
 gcc/tree-if-conv.cc | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index eb981642bae..83b77fd6663 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -2555,10 +2555,17 @@  predicate_load_or_store (gimple_stmt_iterator *gsi, gassign *stmt, tree mask)
 		   ref);
   if (TREE_CODE (lhs) == SSA_NAME)
     {
-      new_stmt
-	= gimple_build_call_internal (IFN_MASK_LOAD, 3, addr,
-				      ptr, mask);
-      gimple_call_set_lhs (new_stmt, lhs);
+      /* Get a zero else value.  This might not be what a target actually uses
+	 but we cannot be sure about which vector mode the vectorizer will
+	 choose.  Therefore, leave the decision whether we need to force the
+	 inactive elements to zero to the vectorizer.  */
+      tree els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
+					  TREE_TYPE (lhs));
+
+      new_stmt = gimple_build_call_internal (IFN_MASK_LOAD, 4, addr,
+					     ptr, mask, els);
+
+      gimple_set_lhs (new_stmt, lhs);
       gimple_set_vuse (new_stmt, gimple_vuse (stmt));
     }
   else
@@ -2876,7 +2883,6 @@  predicate_statements (loop_p loop)
 		new_stmt = predicate_load_or_store (&gsi, stmt, mask);
 	      else
 		new_stmt = predicate_rhs_code (stmt, mask, cond, &ssa_names);
-
 	      gsi_replace (&gsi, new_stmt, true);
 	    }
 	  else if (((lhs = gimple_assign_lhs (stmt)), true)