This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, SH]: Remove an unwanted instruction.
- From: "Naveen H.S." <naveenh at KPITCummins dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 23 May 2006 18:40:48 +0530
- Subject: [PATCH, SH]: Remove an unwanted instruction.
Hi,
The compiler generates an extra instruction "exts.b" which has no
effect on the output. The operation of "exts.b" i.e. sign extension
is been already performed by the preceding instruction "mov". Hence
this extra instruction can be removed as it is not needed.
Please find attached the patch which removes such extra instruction.
Below is a simple testcase that generates the extra unwanted
instruction "exts.b".
=====================================================================
#define SSR (*(volatile unsigned char*)0xfffffe04)
#define SSR_TDRE (1<<7)
void test(void)
{
while(SSR & SSR_TDRE);
}
COMMAND LINE :- sh-elf-gcc -O2 -S
BEFORE applying the patch mov.b @r2,r1
exts.b r1,r1
AFTER patch is applied mov.b @r2,r1.
As the "MOV" instruction does the sign extension of r1, there is no need
of "exts.b" instruction and hence can be removed.
=====================================================================
No new regressions found. Tested on GCC-4.2 snapshot.
=======================Start of Patch================================
ChangeLog
2006-05-23 Naveen.H.S <naveenh@kpitcummins.com>
* gcc/config/h8300/sh.md: Add new Peephole2.
--- gcc/config/sh/sh.md.orig 2006-05-10 15:02:57.000000000 +0530
+++ gcc/config/sh/sh.md 2006-05-10 15:01:30.000000000 +0530
@@ -931,6 +931,16 @@
(if_then_else:DI (match_dup 4) (match_dup 1) (match_dup 2)))]
"")
+(define_peephole2
+ [(set (match_operand:SI 0 "register_operand" "")
+ (sign_extend:SI (match_operand 1 "memory_operand" "")))
+ (set (match_dup 0)
+ (sign_extend:SI (match_operand:QI 2 "register_operand" "")))]
+ "REGNO (operands[0])== REGNO (operands[2])"
+ [(set (match_dup 0)
+ (sign_extend:SI (match_dup 1)))]
+ "")
+
(define_expand "movdicc"
[(set (match_operand:DI 0 "register_operand" "")
(if_then_else:DI (match_operand 1 "comparison_operator" "")
=======================End Of Patch================================
Regards,
Naveen.H.S.
KPIT Cummins Infosystems Ltd,
Pune ( INDIA )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH, H8 and M16C
Series.
The following site also offers free technical support to its users.
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU tools were released on April 1, 2006.