This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch RFC: 3/2 v3] Don't expand a conditional move between identical sources
- From: James Greenhalgh <james dot greenhalgh at arm dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Cc: <nd at arm dot com>, <richard dot guenther at gmail dot com>, <Ramana dot Radhakrishnan at arm dot com>, <bernds_cb1 at t-online dot de>, <ebotcazou at libertysurf dot fr>, <steven at gcc dot gnu dot org>, <rep dot dot dot nop at gmail dot com>, <law at redhat dot com>
- Date: Wed, 20 Jul 2016 10:51:34 +0100
- Subject: [Patch RFC: 3/2 v3] Don't expand a conditional move between identical sources
- Authentication-results: sourceware.org; auth=none
- Nodisclaimer: True
- References: <0f3c74c6-0c1b-f2df-77ce-a2ffc112583d@redhat.com> <1469008295-28884-1-git-send-email-james.greenhalgh@arm.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
Hi,
This patch adds a short-circuit to optabs.c for the case where both
source operands are identical (i.e. we would be assigning the same
value in both branches).
This can show up for the memory optimisation in noce_cmove_arith in ifcvt.c,
if both branches would load from the same address. This is an odd situation
to arrise. It showed up in my csibe runs, but I couldn't reproduce it in
a small test case.
Bootstrapped on x86_64-none-linux-gnu and aarch64-none-linux-gnu with no
issues.
OK?
Thanks,
James
---
2016-07-20 James Greenhalgh <james.greenhalgh@arm.com>
* optabs.c (emit_condiitonal_move): Short circuit for identical
sources.
diff --git a/gcc/optabs.c b/gcc/optabs.c
index 51e10e2..87b4f97 100644
--- a/gcc/optabs.c
+++ b/gcc/optabs.c
@@ -4214,6 +4214,17 @@ emit_conditional_move (rtx target, enum rtx_code code, rtx op0, rtx op1,
enum insn_code icode;
enum rtx_code reversed;
+ /* If the two source operands are identical, that's just a move. */
+
+ if (rtx_equal_p (op2, op3))
+ {
+ if (!target)
+ target = gen_reg_rtx (mode);
+
+ emit_move_insn (target, op3);
+ return target;
+ }
+
/* If one operand is constant, make it the second one. Only do this
if the other operand is not constant as well. */