diff mbox

Improve aarch64 conditional compare usage

Message ID 1486063180.22118.39.camel@caviumnetworks.com
State New
Headers show

Commit Message

Steve Ellcey Feb. 2, 2017, 7:19 p.m. UTC
This patch extends conditional compare code generation for
aarch64.  Right now if there is an AND or OR of two compares, GCC will
generate a compare followed by a conditional compare.  But if you have
a _Bool variable on one side (or both sides) instead of a comparision
than ccmp.c does not recoginize the code as something that can be done
with a conditional compare instruction.  This patch fixes that
limitation.

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.

OK for checkin after 7.0?

Steve Ellcey
sellcey@cavium.com


GCC ChangeLog:

2017-02-02  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-02-02  Steve Ellcey  <sellcey@cavium.com>

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

Patch

diff --git a/gcc/testsuite/gcc.target/aarch64/ccmp_2.c b/gcc/testsuite/gcc.target/aarch64/ccmp_2.c
index e69de29..69616fd 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 -ffinite-math-only" } */
+
+int g(void);
+int h(int a, _Bool c)
+{
+  if (a != 0 && c)
+    return g();
+  return 1;
+}
+
+/* { dg-final { scan-assembler "\tccmp\t" } } */