This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Unoptimal code.
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Umesh Kalappa <umesh dot kalappa0 at gmail dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Tue, 10 Dec 2013 16:20:50 +0100
- Subject: Re: Unoptimal code.
- Authentication-results: sourceware.org; auth=none
- References: <CAGfacvSLOYY6w9CxPOeFDE3xXZiebkQq4htvDJ=pGL9xHcpy9w at mail dot gmail dot com>
On Tue, Dec 10, 2013 at 4:03 PM, Umesh Kalappa <umesh.kalappa0@gmail.com> wrote:
> Hi All,
>
> Below is the patterns defined for the mov and add instruction
> .
> [(set (match_operand:HI 0 "general_mov_operand" "=r,rRA")
> (match_operand:HI 1 "general_mov_operand" "rRAi,ri"))]
> ""
> {
>
> }
> )
>
> (define_insn "addhi3"
> [(set (match_operand:HI 0 "register_operand" "=Ar")
> (plus:HI (match_operand:HI 1 "register_operand" "%0")
> (match_operand:HI 2 "general_mov_operand" "Ar")))]
> ""
> "add\t%0, (%2)"
> )
>
> The problem we stuck with is that the compiler emit unoptimal code for
> the below testcase with -O0 option
>
> int a,b;
>
> int func()
> {
> return a=b;
> }
>
> .s file
>
> ld BC, (a)
> ld WA, (b)
> add WA, BC
> ld (a), WA
> ret
>
> the compiler try to load a and b to the register BC and WA
> respectively in the expand_assignment and add them , then store back
> the result to a.
>
> But if you see the addhi3 definition ,it states that i'm allowed to
> emit instruction like
>
> add WA,(a)
>
> where second operand can be register indirect addressing .
>
> I can write peephole pattern to optimize the emitted code like
>
> .s file
>
> ld WA, (b)
> add WA, (a)
> ld (a), WA
> ret
>
>
> the reason for the unoptimal code is that the code is expanded to
> load the memory contents to the registers and then update the add
> operands accordingly. I don't want this to happen .
>
> I will be glad ,if somebody from the group share their experience or
> through some insights how i can achieve this .
Use -On with n > 0.
Richard.
> Thanks
> ~Umesh