summaryrefslogtreecommitdiff
path: root/gcc/simplify-rtx.c
diff options
context:
space:
mode:
authorktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>2015-07-20 12:51:45 +0000
committerktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>2015-07-20 12:51:45 +0000
commit5ced42f848b676f2528f544c99283bb49d76c5a6 (patch)
treeb199851fd64c33575ae6c054bb768b03fabaf4d8 /gcc/simplify-rtx.c
parentb8783ab25fcbe89a9268537eb21c9173ca79eb97 (diff)
downloadgcc-5ced42f848b676f2528f544c99283bb49d76c5a6.tar.gz
[simplify-rtx][2/2] Simplify - (y ? -x : x) -> (!y ? -x : x)
* simplify-rtx.c (simplify_unary_operation_1, NEG case): (neg (x ? (neg y) : y)) -> !x ? (neg y) : y. * gcc.target/aarch64/neg_abs_1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@225997 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/simplify-rtx.c')
-rw-r--r--gcc/simplify-rtx.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index fde99445e54..4332a42ced4 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -957,6 +957,32 @@ simplify_unary_operation_1 (enum rtx_code code, machine_mode mode, rtx op)
if (GET_CODE (op) == NEG)
return XEXP (op, 0);
+ /* (neg (x ? (neg y) : y)) == !x ? (neg y) : y.
+ If comparison is not reversible use
+ x ? y : (neg y). */
+ if (GET_CODE (op) == IF_THEN_ELSE)
+ {
+ rtx cond = XEXP (op, 0);
+ rtx true_rtx = XEXP (op, 1);
+ rtx false_rtx = XEXP (op, 2);
+
+ if ((GET_CODE (true_rtx) == NEG
+ && rtx_equal_p (XEXP (true_rtx, 0), false_rtx))
+ || (GET_CODE (false_rtx) == NEG
+ && rtx_equal_p (XEXP (false_rtx, 0), true_rtx)))
+ {
+ if (reversed_comparison_code (cond, NULL_RTX) != UNKNOWN)
+ temp = reversed_comparison (cond, mode);
+ else
+ {
+ temp = cond;
+ std::swap (true_rtx, false_rtx);
+ }
+ return simplify_gen_ternary (IF_THEN_ELSE, mode,
+ mode, temp, true_rtx, false_rtx);
+ }
+ }
+
/* (neg (plus X 1)) can become (not X). */
if (GET_CODE (op) == PLUS
&& XEXP (op, 1) == const1_rtx)