diff mbox series

middle-end ifcvt: Allow any const IFN in conditional blocks

Message ID patch-17810-tamar@arm.com
State New
Headers show
Series middle-end ifcvt: Allow any const IFN in conditional blocks | expand

Commit Message

Tamar Christina Oct. 5, 2023, 6:20 p.m. UTC
Hi All,

When ifcvt was initially added masking was not a thing and as such it was
rather conservative in what it supported.

For builtins it only allowed C99 builtin functions which it knew it can fold
away.

These days the vectorizer is able to deal with needing to mask IFNs itself.
vectorizable_call is able vectorize the IFN by emitting a VEC_PERM_EXPR after
the operation to emulate the masking.

This is then used by match.pd to conver the IFN into a masked variant if it's
available.

For these reasons the restriction in ifconvert is no longer require and we
needless block vectorization when we can effectively handle the operations.

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Note: This patch is part of a testseries and tests for it are added in the
AArch64 patch that adds supports for the optab.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	PR tree-optimization/109154
	* tree-if-conv.cc (if_convertible_stmt_p): Allow any const IFN.

--- inline copy of patch -- 
diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index a8c915913aed267edfb3ebd2c530aeca7cf51832..f76e0d8f2e6e0f59073fa8484b0b2c7a6cdc9783 100644




--
diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index a8c915913aed267edfb3ebd2c530aeca7cf51832..f76e0d8f2e6e0f59073fa8484b0b2c7a6cdc9783 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -1129,6 +1129,16 @@ if_convertible_stmt_p (gimple *stmt, vec<data_reference_p> refs)
 		    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.  */
+	int flags = gimple_call_flags (stmt);
+	if ((flags & ECF_CONST)
+	    && !(flags & ECF_LOOPING_CONST_OR_PURE)
+	    && gimple_call_combined_fn (stmt) != CFN_LAST)
+	  return true;
+
 	return false;
       }

Comments

Richard Biener Oct. 6, 2023, 7:14 a.m. UTC | #1
On Thu, 5 Oct 2023, Tamar Christina wrote:

> Hi All,
> 
> When ifcvt was initially added masking was not a thing and as such it was
> rather conservative in what it supported.
> 
> For builtins it only allowed C99 builtin functions which it knew it can fold
> away.
> 
> These days the vectorizer is able to deal with needing to mask IFNs itself.
> vectorizable_call is able vectorize the IFN by emitting a VEC_PERM_EXPR after
> the operation to emulate the masking.
> 
> This is then used by match.pd to conver the IFN into a masked variant if it's
> available.
> 
> For these reasons the restriction in ifconvert is no longer require and we
> needless block vectorization when we can effectively handle the operations.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> 
> Note: This patch is part of a testseries and tests for it are added in the
> AArch64 patch that adds supports for the optab.
> 
> Ok for master?
> 
> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/109154
> 	* tree-if-conv.cc (if_convertible_stmt_p): Allow any const IFN.
> 
> --- inline copy of patch -- 
> diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
> index a8c915913aed267edfb3ebd2c530aeca7cf51832..f76e0d8f2e6e0f59073fa8484b0b2c7a6cdc9783 100644
> --- a/gcc/tree-if-conv.cc
> +++ b/gcc/tree-if-conv.cc
> @@ -1129,6 +1129,16 @@ if_convertible_stmt_p (gimple *stmt, vec<data_reference_p> refs)
>  		    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.  */
> +	int flags = gimple_call_flags (stmt);
> +	if ((flags & ECF_CONST)
> +	    && !(flags & ECF_LOOPING_CONST_OR_PURE)
> +	    && gimple_call_combined_fn (stmt) != CFN_LAST)
> +	  return true;
> +

Can you instead move the check inside the if (fndecl) right before
it, changing it to check gimple_call_combined_fn?

OK with that change.

Richard.

>  	return false;
>        }
>  
> 
> 
> 
> 
>
diff mbox series

Patch

--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -1129,6 +1129,16 @@  if_convertible_stmt_p (gimple *stmt, vec<data_reference_p> refs)
 		    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.  */
+	int flags = gimple_call_flags (stmt);
+	if ((flags & ECF_CONST)
+	    && !(flags & ECF_LOOPING_CONST_OR_PURE)
+	    && gimple_call_combined_fn (stmt) != CFN_LAST)
+	  return true;
+
 	return false;
       }