This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: new peephole2 in arm.md


Hello All,

This patch extends a peephole2 optimization: in arm, move and comparison to
0 (zero) can be solved in parallel. There is a peephole2 optimization defined in arm.md that recognizes one kind of these cases: when two instructions follow each other:
(1) move the value of rs into rd,
(2) compare rd to 0.
However, if rs is compared instead of rd in the 2nd instruction, the
program is identical to the first version, but gcc does not
recognizes the pattern, and leaves the two instructions unchanged. This
patch adds a new peephole2 pattern to arm.md that recognizes the second case, and makes the two instructions parallel.
--
Testcases:

Example (part of assembly of
gcc/testsuite/gcc.c-torture/execute/20020503-1.c compiled with -O2):

Without the patch:

inttostr:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
mov r3, #0
str lr, [sp, #-4]!
cmp r0, #0; <-- (2)
mov lr, r0; <-- (1)
mov ip, r0; <-- (3)
strb r3, [r1, #127]
add r0, r1, #127
ldr r1, .L8
rsblt ip, lr, #0
.L3:
umull r2, r3, r1, ip
...

With the patch:

inttostr:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
mov r3, #0
str lr, [sp, #-4]!
subs lr, r0, #0; <-- (1-2 parallel)
strb r3, [r1, #127]
add r0, r1, #127
ldr r1, .L8
mov ip, lr; <-- (3)
rsblt ip, lr, #0
.L3:
umull r2, r3, r1, ip
...

--
Change log entry:

2003-02-04 Tamas Gergely <gertom@rgai.hu>

* gcc/config/arm/arm.md: new peephole2 pattern added for extending
move and compare parallelization.

--
Testing:

binutils-2.13, gcc-20030127, newlib-1.10.0; HOST=i686-pc-linux-elf, TARGET=arm-unknown-elf

``make check-gcc'' produced the same .sum files with and without the patch.
Tested also on some real applications, no regressions.

--
Patch:

gcc-20030127 and gcc-20030203 contains the same arm.md file, so the patch
can be applied directly to the later snapshot.

Patch attached.
---
*** gcc/config/arm/arm.md.orgn	Mon Feb  3 17:05:52 2003
--- gcc/config/arm/arm.md	Mon Feb  3 17:09:22 2003
***************
*** 8534,8539 ****
--- 8534,8553 ----
    ""
  )
  
+ ; The same as the previous, but with exchanged operands
+ 
+ (define_peephole2
+   [(set (match_operand:SI 0 "s_register_operand" "")
+ 	(match_operand:SI 1 "s_register_operand" ""))
+    (set (reg:CC CC_REGNUM)
+ 	(compare:CC (match_dup 0) (const_int 0)))]
+   "TARGET_ARM
+   "
+   [(parallel [(set (reg:CC CC_REGNUM) (compare:CC (match_dup 1) (const_int 0)))
+ 	      (set (match_dup 0) (match_dup 1))])]
+   ""
+ )
+ 
  ; Peepholes to spot possible load- and store-multiples, if the ordering is
  ; reversed, check that the memory references aren't volatile.
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]