* PATCH: Always avoid lea if possible on x86
@ 2010-08-17 14:50 H.J. Lu
2010-08-17 15:08 ` Bernd Schmidt
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: H.J. Lu @ 2010-08-17 14:50 UTC (permalink / raw)
To: gcc-patches; +Cc: Uros Bizjak, Bernd Schmidt
Hi,
We added ix86_lea_for_add_ok and modified *add<mode>_1 to make sure
that we use LEA on address and ADD on non-address for TARGET_OPT_AGU.
It turned out ADD is always faster than LEA on all processors, except for
TARGET_OPT_AGU. This patch changes *add<mode>_1 and ix86_lea_for_add_ok
to avoid lea for !TARGET_OPT_AGU processors. OK for trunk?
Thanks.
H.J.
---
2010-08-17 H.J. Lu <hongjiu.lu@intel.com>
* config/i386/i386.c (ix86_lea_for_add_ok): For !TARGET_OPT_AGU
or optimizing for size, always avoid lea if possible.
* config/i386/i386.md (*add<mode>_1): Always avoid lea if
possible.
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index b925122..f1d4402 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -14802,10 +14802,10 @@ distance_agu_use (unsigned int regno0, rtx insn)
#define IX86_LEA_PRIORITY 2
/* Return true if it is ok to optimize an ADD operation to LEA
- operation to avoid flag register consumation. For the processors
- like ATOM, if the destination register of LEA holds an actual
- address which will be used soon, LEA is better and otherwise ADD
- is better. */
+ operation to avoid flag register consumation. For most processors,
+ ADD is faster than LEA. For the processors like ATOM, if the
+ destination register of LEA holds an actual address which will be
+ used soon, LEA is better and otherwise ADD is better. */
bool
ix86_lea_for_add_ok (enum rtx_code code ATTRIBUTE_UNUSED,
@@ -14813,16 +14813,14 @@ ix86_lea_for_add_ok (enum rtx_code code ATTRIBUTE_UNUSED,
{
unsigned int regno0 = true_regnum (operands[0]);
unsigned int regno1 = true_regnum (operands[1]);
- unsigned int regno2;
-
- if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
- return regno0 != regno1;
-
- regno2 = true_regnum (operands[2]);
+ unsigned int regno2 = true_regnum (operands[2]);
/* If a = b + c, (a!=b && a!=c), must use lea form. */
if (regno0 != regno1 && regno0 != regno2)
return true;
+
+ if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
+ return false;
else
{
int dist_define, dist_use;
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 0041158..f6ab0e2 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -5813,8 +5813,10 @@
}
default:
- /* Use add as much as possible to replace lea for AGU optimization. */
- if (which_alternative == 2 && TARGET_OPT_AGU)
+ /* This alternative was added for TARGET_OPT_AGU to use add as
+ much as possible. But add is also faster than lea for
+ !TARGET_OPT_AGU. */
+ if (which_alternative == 2)
return "add{<imodesuffix>}\t{%1, %0|%0, %1}";
gcc_assert (rtx_equal_p (operands[0], operands[1]));
@@ -5825,10 +5827,7 @@
}
}
[(set (attr "type")
- (cond [(and (eq_attr "alternative" "2")
- (eq (symbol_ref "TARGET_OPT_AGU") (const_int 0)))
- (const_string "lea")
- (eq_attr "alternative" "3")
+ (cond [(eq_attr "alternative" "3")
(const_string "lea")
(match_operand:SWI48 2 "incdec_operand" "")
(const_string "incdec")
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: Always avoid lea if possible on x86
2010-08-17 14:50 PATCH: Always avoid lea if possible on x86 H.J. Lu
@ 2010-08-17 15:08 ` Bernd Schmidt
2010-08-17 15:21 ` Richard Henderson
2010-08-19 15:42 ` [ix86/gcc-4_5-branch] " H.J. Lu
2 siblings, 0 replies; 6+ messages in thread
From: Bernd Schmidt @ 2010-08-17 15:08 UTC (permalink / raw)
To: H.J. Lu; +Cc: H.J. Lu, gcc-patches, Uros Bizjak
On 08/17/2010 04:49 PM, H.J. Lu wrote:
> We added ix86_lea_for_add_ok and modified *add<mode>_1 to make sure
> that we use LEA on address and ADD on non-address for TARGET_OPT_AGU.
> It turned out ADD is always faster than LEA on all processors, except for
> TARGET_OPT_AGU. This patch changes *add<mode>_1 and ix86_lea_for_add_ok
> to avoid lea for !TARGET_OPT_AGU processors. OK for trunk?
Yes, looks better. Thanks.
Bernd
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: Always avoid lea if possible on x86
2010-08-17 14:50 PATCH: Always avoid lea if possible on x86 H.J. Lu
2010-08-17 15:08 ` Bernd Schmidt
@ 2010-08-17 15:21 ` Richard Henderson
2010-08-17 15:22 ` Bernd Schmidt
2010-08-19 15:42 ` [ix86/gcc-4_5-branch] " H.J. Lu
2 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2010-08-17 15:21 UTC (permalink / raw)
To: H.J. Lu; +Cc: H.J. Lu, gcc-patches, Uros Bizjak, Bernd Schmidt
On 08/17/2010 07:49 AM, H.J. Lu wrote:
> default:
> - /* Use add as much as possible to replace lea for AGU optimization. */
> - if (which_alternative == 2 && TARGET_OPT_AGU)
> + /* This alternative was added for TARGET_OPT_AGU to use add as
> + much as possible. But add is also faster than lea for
> + !TARGET_OPT_AGU. */
> + if (which_alternative == 2)
> return "add{<imodesuffix>}\t{%1, %0|%0, %1}";
>
> gcc_assert (rtx_equal_p (operands[0], operands[1]));
> @@ -5825,10 +5827,7 @@
> }
> }
> [(set (attr "type")
> - (cond [(and (eq_attr "alternative" "2")
> - (eq (symbol_ref "TARGET_OPT_AGU") (const_int 0)))
> - (const_string "lea")
> - (eq_attr "alternative" "3")
> + (cond [(eq_attr "alternative" "3")
> (const_string "lea")
> (match_operand:SWI48 2 "incdec_operand" "")
> (const_string "incdec")
Is there any reason not to remove alternative 2 now that
you're not doing anything special with it?
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: Always avoid lea if possible on x86
2010-08-17 15:21 ` Richard Henderson
@ 2010-08-17 15:22 ` Bernd Schmidt
2010-08-17 15:24 ` Richard Henderson
0 siblings, 1 reply; 6+ messages in thread
From: Bernd Schmidt @ 2010-08-17 15:22 UTC (permalink / raw)
To: Richard Henderson; +Cc: H.J. Lu, H.J. Lu, gcc-patches, Uros Bizjak
On 08/17/2010 05:18 PM, Richard Henderson wrote:
> Is there any reason not to remove alternative 2 now that
> you're not doing anything special with it?
If I understood things correctly, the problem was that in this case we'd
match what is now alternative 3, and generate lea.
Bernd
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: Always avoid lea if possible on x86
2010-08-17 15:22 ` Bernd Schmidt
@ 2010-08-17 15:24 ` Richard Henderson
0 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2010-08-17 15:24 UTC (permalink / raw)
To: Bernd Schmidt; +Cc: H.J. Lu, H.J. Lu, gcc-patches, Uros Bizjak
On 08/17/2010 08:20 AM, Bernd Schmidt wrote:
> On 08/17/2010 05:18 PM, Richard Henderson wrote:
>> Is there any reason not to remove alternative 2 now that
>> you're not doing anything special with it?
>
> If I understood things correctly, the problem was that in this case we'd
> match what is now alternative 3, and generate lea.
Ah, right, I see. The patch is ok.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ix86/gcc-4_5-branch] PATCH: Always avoid lea if possible on x86
2010-08-17 14:50 PATCH: Always avoid lea if possible on x86 H.J. Lu
2010-08-17 15:08 ` Bernd Schmidt
2010-08-17 15:21 ` Richard Henderson
@ 2010-08-19 15:42 ` H.J. Lu
2 siblings, 0 replies; 6+ messages in thread
From: H.J. Lu @ 2010-08-19 15:42 UTC (permalink / raw)
To: gcc-patches
On Tue, Aug 17, 2010 at 07:49:25AM -0700, H.J. Lu wrote:
> Hi,
>
> We added ix86_lea_for_add_ok and modified *add<mode>_1 to make sure
> that we use LEA on address and ADD on non-address for TARGET_OPT_AGU.
> It turned out ADD is always faster than LEA on all processors, except for
> TARGET_OPT_AGU. This patch changes *add<mode>_1 and ix86_lea_for_add_ok
> to avoid lea for !TARGET_OPT_AGU processors. OK for trunk?
>
> Thanks.
>
>
> H.J.
> ---
> 2010-08-17 H.J. Lu <hongjiu.lu@intel.com>
>
> * config/i386/i386.c (ix86_lea_for_add_ok): For !TARGET_OPT_AGU
> or optimizing for size, always avoid lea if possible.
>
> * config/i386/i386.md (*add<mode>_1): Always avoid lea if
> possible.
>
I backported it to ix86/gcc-4_5-branch.
H.J.
---
diff --git a/gcc/ChangeLog.ix86 b/gcc/ChangeLog.ix86
index c5ba9c9..116f87a 100644
--- a/gcc/ChangeLog.ix86
+++ b/gcc/ChangeLog.ix86
@@ -1,3 +1,14 @@
+2010-08-19 H.J. Lu <hongjiu.lu@intel.com>
+
+ Backport from mainline
+ 2010-08-17 H.J. Lu <hongjiu.lu@intel.com>
+
+ * config/i386/i386.c (ix86_lea_for_add_ok): For !TARGET_OPT_AGU
+ or optimizing for size, always avoid lea if possible.
+
+ * config/i386/i386.md (*add<mode>_1): Always avoid lea if
+ possible.
+
2010-08-12 H.J. Lu <hongjiu.lu@intel.com>
Backport from mainline
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 4b7a061..7265465 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -13902,10 +13902,10 @@ distance_agu_use (unsigned int regno0, rtx insn)
#define IX86_LEA_PRIORITY 2
/* Return true if it is ok to optimize an ADD operation to LEA
- operation to avoid flag register consumation. For the processors
- like ATOM, if the destination register of LEA holds an actual
- address which will be used soon, LEA is better and otherwise ADD
- is better. */
+ operation to avoid flag register consumation. For most processors,
+ ADD is faster than LEA. For the processors like ATOM, if the
+ destination register of LEA holds an actual address which will be
+ used soon, LEA is better and otherwise ADD is better. */
bool
ix86_lea_for_add_ok (enum rtx_code code ATTRIBUTE_UNUSED,
@@ -13913,17 +13913,15 @@ ix86_lea_for_add_ok (enum rtx_code code ATTRIBUTE_UNUSED,
{
unsigned int regno0 = true_regnum (operands[0]);
unsigned int regno1 = true_regnum (operands[1]);
- unsigned int regno2;
-
- if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
- return regno0 != regno1;
-
- regno2 = true_regnum (operands[2]);
+ unsigned int regno2 = true_regnum (operands[2]);
/* If a = b + c, (a!=b && a!=c), must use lea form. */
if (regno0 != regno1 && regno0 != regno2)
return true;
- else
+
+ if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
+ return false;
+ else
{
int dist_define, dist_use;
dist_define = distance_non_agu_define (regno1, regno2, insn);
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index d092a4a..2f1b25e 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -6015,8 +6015,10 @@
}
default:
- /* Use add as much as possible to replace lea for AGU optimization. */
- if (which_alternative == 2 && TARGET_OPT_AGU)
+ /* This alternative was added for TARGET_OPT_AGU to use add as
+ much as possible. But add is also faster than lea for
+ !TARGET_OPT_AGU. */
+ if (which_alternative == 2)
return "add{<imodesuffix>}\t{%1, %0|%0, %1}";
gcc_assert (rtx_equal_p (operands[0], operands[1]));
@@ -6038,10 +6040,7 @@
}
}
[(set (attr "type")
- (cond [(and (eq_attr "alternative" "2")
- (eq (symbol_ref "TARGET_OPT_AGU") (const_int 0)))
- (const_string "lea")
- (eq_attr "alternative" "3")
+ (cond [(eq_attr "alternative" "3")
(const_string "lea")
; Current assemblers are broken and do not allow @GOTOFF in
; ought but a memory context.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-08-19 14:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-17 14:50 PATCH: Always avoid lea if possible on x86 H.J. Lu
2010-08-17 15:08 ` Bernd Schmidt
2010-08-17 15:21 ` Richard Henderson
2010-08-17 15:22 ` Bernd Schmidt
2010-08-17 15:24 ` Richard Henderson
2010-08-19 15:42 ` [ix86/gcc-4_5-branch] " H.J. Lu
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).