public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH/AARCH64] Improve aarch64 conditional compare usage
@ 2017-06-16 17:06 Steve Ellcey
  2017-06-20 13:58 ` James Greenhalgh
  0 siblings, 1 reply; 6+ messages in thread
From: Steve Ellcey @ 2017-06-16 17:06 UTC (permalink / raw)
  To: gcc-patches


https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00021.html

Ping.

Steve Ellcey
sellcey@cavium.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH/AARCH64] Improve aarch64 conditional compare usage
  2017-06-16 17:06 [PATCH/AARCH64] Improve aarch64 conditional compare usage Steve Ellcey
@ 2017-06-20 13:58 ` James Greenhalgh
  2017-06-20 15:21   ` Steve Ellcey
  0 siblings, 1 reply; 6+ messages in thread
From: James Greenhalgh @ 2017-06-20 13:58 UTC (permalink / raw)
  To: Steve Ellcey; +Cc: gcc-patches, nd

On Fri, Jun 16, 2017 at 10:06:51AM -0700, Steve Ellcey wrote:
> 
> https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00021.html
> 
> Ping.

Hi Steve,

These changes all look like they are to the tree pass rather than to the
AArch64 back end. Maybe reposting it without the AArch64 tag will get it
more visibility from people other than the AArch64 maintainers?

Cheers,
James

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH/AARCH64] Improve aarch64 conditional compare usage
  2017-06-20 13:58 ` James Greenhalgh
@ 2017-06-20 15:21   ` Steve Ellcey
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Ellcey @ 2017-06-20 15:21 UTC (permalink / raw)
  To: James Greenhalgh; +Cc: gcc-patches, nd

On Tue, 2017-06-20 at 14:58 +0100, James Greenhalgh wrote:
> On Fri, Jun 16, 2017 at 10:06:51AM -0700, Steve Ellcey wrote:
> > 
> > 
> > https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00021.html
> > 
> > Ping.
> Hi Steve,
> 
> These changes all look like they are to the tree pass rather than to the
> AArch64 back end. Maybe reposting it without the AArch64 tag will get it
> more visibility from people other than the AArch64 maintainers?
> 
> Cheers,
> James

Someone else made the same suggestion so I re-pinged here:

https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01338.html

With the subject "[PATCH] Ping of ccmp.c (conditional compare) patch"

Steve Ellcey
sellcey@cavium.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH/AARCH64] Improve aarch64 conditional compare usage
  2017-06-27 22:46 ` Jeff Law
@ 2017-06-29 18:30   ` Steve Ellcey
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Ellcey @ 2017-06-29 18:30 UTC (permalink / raw)
  To: Jeff Law, gcc-patches

On Tue, 2017-06-27 at 16:45 -0600, Jeff Law wrote:

> > +  /* If we have a boolean variable allow it and generate a compare
> > +     to zero reg when expanding.  */
> > +  if (!g)
> > +    return (TREE_CODE (TREE_TYPE (t)) == BOOLEAN_TYPE);
> Depending on how you use T, you might be better off checking T's range
> and considering anything with the [0,1] range as a boolean.  That would
> also pick up the case where T was set via a comparison, or the output of
> a PHI with arguments that are all [0,1], etc.  I've found that to be a
> useful improvement in a couple places.
> 
> See ssa_name_has_boolean_range.  I don't consider it a requirement for
> this patch to go forward, but more something you might want to
> investigate as a future improvement.
> 
> OK for the trunk.  Sorry about the delay.
> 
> jeff

Thanks Jeff, I checked this in.  I hadn't considered integers with a
restricted range but it might be worth adding.  I will look into that.

Steve Ellcey
sellcey@cavium.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH/AARCH64] Improve aarch64 conditional compare usage
  2017-05-01 17:16 Steve Ellcey
@ 2017-06-27 22:46 ` Jeff Law
  2017-06-29 18:30   ` Steve Ellcey
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Law @ 2017-06-27 22:46 UTC (permalink / raw)
  To: sellcey, gcc-patches

On 05/01/2017 11:16 AM, Steve Ellcey wrote:
> This is a resubmittal of an earlier patch
> (https://gcc.gnu.org/ml/gcc-patches/2017-02/msg00203.html) to improve the
> use of ccmp (conditional compare) on aarch64.  I made a couple of tweaks
> after the first submittal and retested now that we are back in stage 1.
> 
> Most of the changes are restructuring the code to allow the change and do
> not affect the actual output.  The actual behavour change is in
> ccmp_tree_comparison_p where we recoginize a boolean variable as well
> as a compare expression as code that can be done with a conditionial
> compare and in get_compare_parts where we treat a boolean variable X
> as 'X != 0' and generate that comparision.
> 
> Since the code in ccmp.c is ony used when TARGET_GEN_CCMP_FIRST is set
> and TARGET_GEN_CCMP_FIRST is only set for aarch64 this change will only
> affect aarch64.
> 
> Tested with no regressions and a new test is added to verify that we
> generate a ccmp instruction with the change.  I ran the SPEC2006 int
> tests and got a .02 increase in the SPECmark on a ThunderX box. The
> biggest increases were in mcf and astar.  One test, xlancbmk, did slow
> down but the overall SPEC result was a speedup.
> 
> OK for checkin?
> 
> Steve Ellcey
> sellcey@cavium.com
> 
> 
> GCC ChangeLog:
> 
> 2017-05-01  Steve Ellcey  <sellcey@cavium.com>
> 
> 	* ccmp.c (ccmp_tree_comparison_p): New function.
> 	(ccmp_candidate_p): Update to use above function.
> 	(get_compare_parts): New function.
> 	(expand_ccmp_next): Update to use new functions.
> 	(expand_ccmp_expr_1): Take tree arg instead of gimple, update to use
> 	new functions.
> 	(expand_ccmp_expr): Pass tree instead of gimple to expand_ccmp_expr_1,
> 	take mode as argument.
> 	* ccmp.h (expand_ccmp_expr): Add mode as argument.
> 	* expr.c (expand_expr_real_1): Pass mode as argument.
> 
> GCC Testsuite ChangeLog:
> 
> 
> 2017-05-01  Steve Ellcey  <sellcey@cavium.com>
> 
> 	* gcc.target/aarch64/ccmp_2.c: New test.
> 
> 
> gcc.ccmp.patch
> 
> 
> diff --git a/gcc/ccmp.c b/gcc/ccmp.c
> index 92ca133..4fa3ebd 100644
> --- a/gcc/ccmp.c
> +++ b/gcc/ccmp.c
> @@ -38,6 +38,29 @@ along with GCC; see the file COPYING3.  If not see
>  #include "ccmp.h"
>  #include "predict.h"
>  
> +/* Check whether T is a simple boolean variable or a SSA name
> +   set by a comparison operator in the same basic block.  */
> +static bool
> +ccmp_tree_comparison_p (tree t, basic_block bb)
> +{
> +  gimple *g = get_gimple_for_ssa_name (t);
> +  tree_code tcode;
> +
> +  /* If we have a boolean variable allow it and generate a compare
> +     to zero reg when expanding.  */
> +  if (!g)
> +    return (TREE_CODE (TREE_TYPE (t)) == BOOLEAN_TYPE);
Depending on how you use T, you might be better off checking T's range
and considering anything with the [0,1] range as a boolean.  That would
also pick up the case where T was set via a comparison, or the output of
a PHI with arguments that are all [0,1], etc.  I've found that to be a
useful improvement in a couple places.

See ssa_name_has_boolean_range.  I don't consider it a requirement for
this patch to go forward, but more something you might want to
investigate as a future improvement.

OK for the trunk.  Sorry about the delay.

jeff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH/AARCH64] Improve aarch64 conditional compare usage
@ 2017-05-01 17:16 Steve Ellcey
  2017-06-27 22:46 ` Jeff Law
  0 siblings, 1 reply; 6+ messages in thread
From: Steve Ellcey @ 2017-05-01 17:16 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1894 bytes --]

This is a resubmittal of an earlier patch
(https://gcc.gnu.org/ml/gcc-patches/2017-02/msg00203.html) to improve the
use of ccmp (conditional compare) on aarch64.  I made a couple of tweaks
after the first submittal and retested now that we are back in stage 1.

Most of the changes are restructuring the code to allow the change and do
not affect the actual output.  The actual behavour change is in
ccmp_tree_comparison_p where we recoginize a boolean variable as well
as a compare expression as code that can be done with a conditionial
compare and in get_compare_parts where we treat a boolean variable X
as 'X != 0' and generate that comparision.

Since the code in ccmp.c is ony used when TARGET_GEN_CCMP_FIRST is set
and TARGET_GEN_CCMP_FIRST is only set for aarch64 this change will only
affect aarch64.

Tested with no regressions and a new test is added to verify that we
generate a ccmp instruction with the change.  I ran the SPEC2006 int
tests and got a .02 increase in the SPECmark on a ThunderX box. The
biggest increases were in mcf and astar.  One test, xlancbmk, did slow
down but the overall SPEC result was a speedup.

OK for checkin?

Steve Ellcey
sellcey@cavium.com


GCC ChangeLog:

2017-05-01  Steve Ellcey  <sellcey@cavium.com>

	* ccmp.c (ccmp_tree_comparison_p): New function.
	(ccmp_candidate_p): Update to use above function.
	(get_compare_parts): New function.
	(expand_ccmp_next): Update to use new functions.
	(expand_ccmp_expr_1): Take tree arg instead of gimple, update to use
	new functions.
	(expand_ccmp_expr): Pass tree instead of gimple to expand_ccmp_expr_1,
	take mode as argument.
	* ccmp.h (expand_ccmp_expr): Add mode as argument.
	* expr.c (expand_expr_real_1): Pass mode as argument.

GCC Testsuite ChangeLog:


2017-05-01  Steve Ellcey  <sellcey@cavium.com>

	* gcc.target/aarch64/ccmp_2.c: New test.

[-- Attachment #2: gcc.ccmp.patch --]
[-- Type: text/x-patch, Size: 11027 bytes --]

diff --git a/gcc/ccmp.c b/gcc/ccmp.c
index 92ca133..4fa3ebd 100644
--- a/gcc/ccmp.c
+++ b/gcc/ccmp.c
@@ -38,6 +38,29 @@ along with GCC; see the file COPYING3.  If not see
 #include "ccmp.h"
 #include "predict.h"
 
+/* Check whether T is a simple boolean variable or a SSA name
+   set by a comparison operator in the same basic block.  */
+static bool
+ccmp_tree_comparison_p (tree t, basic_block bb)
+{
+  gimple *g = get_gimple_for_ssa_name (t);
+  tree_code tcode;
+
+  /* If we have a boolean variable allow it and generate a compare
+     to zero reg when expanding.  */
+  if (!g)
+    return (TREE_CODE (TREE_TYPE (t)) == BOOLEAN_TYPE);
+
+  /* Check to see if SSA name is set by a comparison operator in
+     the same basic block.  */ 
+  if (!is_gimple_assign (g))
+    return false;
+  if (bb != gimple_bb (g))
+    return false;
+  tcode = gimple_assign_rhs_code (g);
+  return TREE_CODE_CLASS (tcode) == tcc_comparison;
+}
+
 /* The following functions expand conditional compare (CCMP) instructions.
    Here is a short description about the over all algorithm:
      * ccmp_candidate_p is used to identify the CCMP candidate
@@ -71,49 +94,69 @@ along with GCC; see the file COPYING3.  If not see
 static bool
 ccmp_candidate_p (gimple *g)
 {
-  tree rhs = gimple_assign_rhs_to_tree (g);
+  tree rhs;
   tree lhs, op0, op1;
   gimple *gs0, *gs1;
-  tree_code tcode, tcode0, tcode1;
-  tcode = TREE_CODE (rhs);
+  tree_code tcode;
+  basic_block bb;
+
+  if (!g)
+    return false;
 
+  rhs = gimple_assign_rhs_to_tree (g);
+  tcode = TREE_CODE (rhs);
   if (tcode != BIT_AND_EXPR && tcode != BIT_IOR_EXPR)
     return false;
 
   lhs = gimple_assign_lhs (g);
   op0 = TREE_OPERAND (rhs, 0);
   op1 = TREE_OPERAND (rhs, 1);
+  bb = gimple_bb (g);
 
   if ((TREE_CODE (op0) != SSA_NAME) || (TREE_CODE (op1) != SSA_NAME)
       || !has_single_use (lhs))
     return false;
 
-  gs0 = get_gimple_for_ssa_name (op0);
-  gs1 = get_gimple_for_ssa_name (op1);
-  if (!gs0 || !gs1 || !is_gimple_assign (gs0) || !is_gimple_assign (gs1)
-      /* g, gs0 and gs1 must be in the same basic block, since current stage
-	 is out-of-ssa.  We can not guarantee the correctness when forwording
-	 the gs0 and gs1 into g whithout DATAFLOW analysis.  */
-      || gimple_bb (gs0) != gimple_bb (gs1)
-      || gimple_bb (gs0) != gimple_bb (g))
-    return false;
+  gs0 = get_gimple_for_ssa_name (op0); /* gs0 may be NULL */
+  gs1 = get_gimple_for_ssa_name (op1); /* gs1 may be NULL */
 
-  tcode0 = gimple_assign_rhs_code (gs0);
-  tcode1 = gimple_assign_rhs_code (gs1);
-  if (TREE_CODE_CLASS (tcode0) == tcc_comparison
-      && TREE_CODE_CLASS (tcode1) == tcc_comparison)
+  if (ccmp_tree_comparison_p (op0, bb) && ccmp_tree_comparison_p (op1, bb))
     return true;
-  if (TREE_CODE_CLASS (tcode0) == tcc_comparison
-      && ccmp_candidate_p (gs1))
+  if (ccmp_tree_comparison_p (op0, bb) && ccmp_candidate_p (gs1))
     return true;
-  else if (TREE_CODE_CLASS (tcode1) == tcc_comparison
-	   && ccmp_candidate_p (gs0))
+  if (ccmp_tree_comparison_p (op1, bb) && ccmp_candidate_p (gs0))
     return true;
   /* We skip ccmp_candidate_p (gs1) && ccmp_candidate_p (gs0) since
-     there is no way to set the CC flag.  */
+     there is no way to set and maintain the CC flag on both sides of
+     the logical operator at the same time.  */
   return false;
 }
 
+/* Extract the comparison we want to do from the tree.  */
+void
+get_compare_parts (tree t, int *up, rtx_code *rcode,
+		   tree *rhs1, tree *rhs2)
+{
+  tree_code code;
+  gimple *g = get_gimple_for_ssa_name (t);
+  if (g)
+    {
+      *up = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (g)));
+      code = gimple_assign_rhs_code (g);
+      *rcode = get_rtx_code (code, *up);
+      *rhs1 = gimple_assign_rhs1 (g);
+      *rhs2 = gimple_assign_rhs2 (g);
+    }
+  else
+    {
+      /* If g is not a comparison operator create a compare to zero.  */
+      *up = 1;
+      *rcode = NE;
+      *rhs1 = t;
+      *rhs2 = build_zero_cst (TREE_TYPE (t));
+    }
+}
+
 /* PREV is a comparison with the CC register which represents the
    result of the previous CMP or CCMP.  The function expands the
    next compare based on G which is ANDed/ORed with the previous
@@ -121,20 +164,16 @@ ccmp_candidate_p (gimple *g)
    PREP_SEQ returns all insns to prepare opearands for compare.
    GEN_SEQ returns all compare insns.  */
 static rtx
-expand_ccmp_next (gimple *g, tree_code code, rtx prev,
+expand_ccmp_next (tree op, tree_code code, rtx prev,
 		  rtx_insn **prep_seq, rtx_insn **gen_seq)
 {
   rtx_code rcode;
-  int unsignedp = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (g)));
-
-  gcc_assert (code == BIT_AND_EXPR || code == BIT_IOR_EXPR);
-
-  rcode = get_rtx_code (gimple_assign_rhs_code (g), unsignedp);
+  int unsignedp;
+  tree rhs1, rhs2;
 
+  get_compare_parts(op, &unsignedp, &rcode, &rhs1, &rhs2);
   return targetm.gen_ccmp_next (prep_seq, gen_seq, prev, rcode,
-				gimple_assign_rhs1 (g),
-				gimple_assign_rhs2 (g),
-				get_rtx_code (code, 0));
+				rhs1, rhs2, get_rtx_code (code, 0));
 }
 
 /* Expand conditional compare gimple G.  A typical CCMP sequence is like:
@@ -153,39 +192,42 @@ expand_ccmp_expr_1 (gimple *g, rtx_insn **prep_seq, rtx_insn **gen_seq)
 {
   tree exp = gimple_assign_rhs_to_tree (g);
   tree_code code = TREE_CODE (exp);
-  gimple *gs0 = get_gimple_for_ssa_name (TREE_OPERAND (exp, 0));
-  gimple *gs1 = get_gimple_for_ssa_name (TREE_OPERAND (exp, 1));
+  basic_block bb = gimple_bb (g);
+
+  tree op0 = TREE_OPERAND (exp, 0);
+  tree op1 = TREE_OPERAND (exp, 1);
+  gimple *gs0 = get_gimple_for_ssa_name (op0);
+  gimple *gs1 = get_gimple_for_ssa_name (op1);
   rtx tmp;
-  tree_code code0 = gimple_assign_rhs_code (gs0);
-  tree_code code1 = gimple_assign_rhs_code (gs1);
 
   gcc_assert (code == BIT_AND_EXPR || code == BIT_IOR_EXPR);
-  gcc_assert (gs0 && gs1 && is_gimple_assign (gs0) && is_gimple_assign (gs1));
 
-  if (TREE_CODE_CLASS (code0) == tcc_comparison)
+  if (ccmp_tree_comparison_p (op0, bb))
     {
-      if (TREE_CODE_CLASS (code1) == tcc_comparison)
+      if (ccmp_tree_comparison_p (op1, bb))
 	{
 	  int unsignedp0, unsignedp1;
 	  rtx_code rcode0, rcode1;
+	  tree logical_op0_rhs1, logical_op0_rhs2;
+	  tree logical_op1_rhs1, logical_op1_rhs2;
 	  int speed_p = optimize_insn_for_speed_p ();
+
 	  rtx tmp2 = NULL_RTX, ret = NULL_RTX, ret2 = NULL_RTX;
 	  unsigned cost1 = MAX_COST;
 	  unsigned cost2 = MAX_COST;
 
-	  unsignedp0 = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (gs0)));
-	  unsignedp1 = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (gs1)));
-	  rcode0 = get_rtx_code (code0, unsignedp0);
-	  rcode1 = get_rtx_code (code1, unsignedp1);
+	  get_compare_parts (op0, &unsignedp0, &rcode0,
+			     &logical_op0_rhs1, &logical_op0_rhs2);
+
+	  get_compare_parts (op1, &unsignedp1, &rcode1,
+			     &logical_op1_rhs1, &logical_op1_rhs2);
 
 	  rtx_insn *prep_seq_1, *gen_seq_1;
 	  tmp = targetm.gen_ccmp_first (&prep_seq_1, &gen_seq_1, rcode0,
-					gimple_assign_rhs1 (gs0),
-					gimple_assign_rhs2 (gs0));
-
+					logical_op0_rhs1, logical_op0_rhs2);
 	  if (tmp != NULL)
 	    {
-	      ret = expand_ccmp_next (gs1, code, tmp, &prep_seq_1, &gen_seq_1);
+	      ret = expand_ccmp_next (op1, code, tmp, &prep_seq_1, &gen_seq_1);
 	      cost1 = seq_cost (prep_seq_1, speed_p);
 	      cost1 += seq_cost (gen_seq_1, speed_p);
 	    }
@@ -197,27 +239,22 @@ expand_ccmp_expr_1 (gimple *g, rtx_insn **prep_seq, rtx_insn **gen_seq)
 	  rtx_insn *prep_seq_2, *gen_seq_2;
 	  if (tmp == NULL || cost1 < COSTS_N_INSNS (25))
 	    tmp2 = targetm.gen_ccmp_first (&prep_seq_2, &gen_seq_2, rcode1,
-					   gimple_assign_rhs1 (gs1),
-					   gimple_assign_rhs2 (gs1));
-
+					   logical_op1_rhs1, logical_op1_rhs2);
 	  if (!tmp && !tmp2)
 	    return NULL_RTX;
-
 	  if (tmp2 != NULL)
 	    {
-	      ret2 = expand_ccmp_next (gs0, code, tmp2, &prep_seq_2,
+	      ret2 = expand_ccmp_next (op0, code, tmp2, &prep_seq_2,
 				       &gen_seq_2);
 	      cost2 = seq_cost (prep_seq_2, speed_p);
 	      cost2 += seq_cost (gen_seq_2, speed_p);
 	    }
-
 	  if (cost2 < cost1)
 	    {
 	      *prep_seq = prep_seq_2;
 	      *gen_seq = gen_seq_2;
 	      return ret2;
 	    }
-
 	  *prep_seq = prep_seq_1;
 	  *gen_seq = gen_seq_1;
 	  return ret;
@@ -227,28 +264,18 @@ expand_ccmp_expr_1 (gimple *g, rtx_insn **prep_seq, rtx_insn **gen_seq)
 	  tmp = expand_ccmp_expr_1 (gs1, prep_seq, gen_seq);
 	  if (!tmp)
 	    return NULL_RTX;
-
-	  return expand_ccmp_next (gs0, code, tmp, prep_seq, gen_seq);
+	  return expand_ccmp_next (op0, code, tmp, prep_seq, gen_seq);
 	}
     }
   else
     {
       gcc_assert (gimple_assign_rhs_code (gs0) == BIT_AND_EXPR
                   || gimple_assign_rhs_code (gs0) == BIT_IOR_EXPR);
-
-      if (TREE_CODE_CLASS (gimple_assign_rhs_code (gs1)) == tcc_comparison)
-	{
-	  tmp = expand_ccmp_expr_1 (gs0, prep_seq, gen_seq);
-	  if (!tmp)
-	    return NULL_RTX;
-
-	  return expand_ccmp_next (gs1, code, tmp, prep_seq, gen_seq);
-	}
-      else
-	{
-	  gcc_assert (gimple_assign_rhs_code (gs1) == BIT_AND_EXPR
-		      || gimple_assign_rhs_code (gs1) == BIT_IOR_EXPR);
-	}
+      gcc_assert (ccmp_tree_comparison_p (op1, bb));
+      tmp = expand_ccmp_expr_1 (gs0, prep_seq, gen_seq);
+      if (!tmp)
+	return NULL_RTX;
+      return expand_ccmp_next (op1, code, tmp, prep_seq, gen_seq);
     }
 
   return NULL_RTX;
@@ -258,7 +285,7 @@ expand_ccmp_expr_1 (gimple *g, rtx_insn **prep_seq, rtx_insn **gen_seq)
    Return NULL_RTX if G is not a legal candidate or expand fail.
    Otherwise return the target.  */
 rtx
-expand_ccmp_expr (gimple *g)
+expand_ccmp_expr (gimple *g, machine_mode mode)
 {
   rtx_insn *last;
   rtx tmp;
@@ -275,7 +302,6 @@ expand_ccmp_expr (gimple *g)
     {
       insn_code icode;
       machine_mode cc_mode = CCmode;
-      tree lhs = gimple_assign_lhs (g);
       rtx_code cmp_code = GET_CODE (tmp);
 
 #ifdef SELECT_CC_MODE
@@ -284,7 +310,6 @@ expand_ccmp_expr (gimple *g)
       icode = optab_handler (cstore_optab, cc_mode);
       if (icode != CODE_FOR_nothing)
 	{
-	  machine_mode mode = TYPE_MODE (TREE_TYPE (lhs));
 	  rtx target = gen_reg_rtx (mode);
 
 	  emit_insn (prep_seq);
@@ -300,4 +325,3 @@ expand_ccmp_expr (gimple *g)
   delete_insns_since (last);
   return NULL_RTX;
 }
-
diff --git a/gcc/ccmp.h b/gcc/ccmp.h
index bc1aafb..93d1049 100644
--- a/gcc/ccmp.h
+++ b/gcc/ccmp.h
@@ -20,6 +20,6 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_CCMP_H
 #define GCC_CCMP_H
 
-extern rtx expand_ccmp_expr (gimple *);
+extern rtx expand_ccmp_expr (gimple *, machine_mode);
 
 #endif  /* GCC_CCMP_H  */
diff --git a/gcc/expr.c b/gcc/expr.c
index c5c50e0..6594f12 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -9757,7 +9757,7 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
 	      if (targetm.gen_ccmp_first)
 		{
 		  gcc_checking_assert (targetm.gen_ccmp_next != NULL);
-		  r = expand_ccmp_expr (g);
+		  r = expand_ccmp_expr (g, mode);
 		  if (r)
 		    break;
 		}

[-- Attachment #3: gcc.ccmp.test.patch --]
[-- Type: text/x-patch, Size: 442 bytes --]

diff --git a/gcc/testsuite/gcc.target/aarch64/ccmp_2.c b/gcc/testsuite/gcc.target/aarch64/ccmp_2.c
index e69de29..77ab020 100644
--- a/gcc/testsuite/gcc.target/aarch64/ccmp_2.c
+++ b/gcc/testsuite/gcc.target/aarch64/ccmp_2.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int g(void);
+int h(int a, _Bool c)
+{
+  if (a != 0 && c)
+    return g();
+  return 1;
+}
+
+/* { dg-final { scan-assembler "\tccmp\t" } } */

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-06-29 18:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-16 17:06 [PATCH/AARCH64] Improve aarch64 conditional compare usage Steve Ellcey
2017-06-20 13:58 ` James Greenhalgh
2017-06-20 15:21   ` Steve Ellcey
  -- strict thread matches above, loose matches on Subject: below --
2017-05-01 17:16 Steve Ellcey
2017-06-27 22:46 ` Jeff Law
2017-06-29 18:30   ` Steve Ellcey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).