[patch] m68k: Fix PR target/19201.
Kazu Hirata
kazu@codesourcery.com
Mon Nov 28 01:21:00 GMT 2005
Hi,
Attached is a patch to fix PR target/19201.
Consider:
struct X {
char *a;
int b;
};
void
f (struct X *x)
{
x->a[x->b] = 0;
}
m68k-elf-gcc -O2 -fomit-frame-pointer generates:
f:
move.l 4(%sp),%a0
move.l (%a0),%a1
move.l 4(%a0),%a0
clr.b (%a0,%a1.l)
rts
With this patch,
f:
move.l 4(%sp),%a0
move.l (%a0),%a1
add.l 4(%a0),%a1
clr.b (%a1)
rts
The patch performs this transformation with peephole2.
Tested on m68k. OK to apply?
Kazu Hirata
2005-11-28 Kazu Hirata <kazu@codesourcery.com>
* config/m68k/m68k.md (a peephole2): New.
* config/m68k/predicates.md (address_register_operand): Likewise.
Index: config/m68k/m68k.md
===================================================================
--- config/m68k/m68k.md (revision 107541)
+++ config/m68k/m68k.md (working copy)
@@ -7092,3 +7092,40 @@ (define_insn "conditional_trap"
default: gcc_unreachable ();
}
})
+
+; Convert
+;
+; move.l 4(%a0),%a0
+; clr.b (%a0,%a1.l)
+;
+; into
+;
+; add.l 4(%a0),%a1
+; clr.b (%a1)
+;
+; The latter is shorter. It is faster on all models except m68060.
+
+(define_peephole2
+ [(set (match_operand:SI 0 "register_operand" "")
+ (mem:SI (plus:SI (match_operand:SI 1 "register_operand" "")
+ (match_operand:SI 2 "const_int_operand" ""))))
+ (set (mem:QI (plus:SI (match_operand:SI 3 "register_operand" "")
+ (match_operand:SI 4 "register_operand" "")))
+ (const_int 0))]
+ "/* We'll always win in terms of size. We don't win on mc68060 in
+ terms of performance. */
+ (optimize_size || !TARGET_68060)
+ /* Make sure operands[5] will be an address register. */
+ && ((operands[0] == operands[3]
+ && address_register_operand (operands[4], SImode))
+ || (operands[0] == operands[4]
+ && address_register_operand (operands[3], SImode)))
+ && peep2_reg_dead_p (2, operands[3])
+ && peep2_reg_dead_p (2, operands[4])"
+ [(set (match_dup 5)
+ (plus:SI (match_dup 5)
+ (mem:SI (plus:SI (match_dup 1)
+ (match_dup 2)))))
+ (set (mem:QI (match_dup 5))
+ (const_int 0))]
+ "operands[5] = (operands[0] == operands[3]) ? operands[4] : operands[3];")
Index: config/m68k/predicates.md
===================================================================
--- config/m68k/predicates.md (revision 107541)
+++ config/m68k/predicates.md (working copy)
@@ -170,3 +170,9 @@ (define_predicate "post_inc_operand"
(define_predicate "pre_dec_operand"
(and (match_code "mem")
(match_test "GET_CODE (XEXP (op, 0)) == PRE_DEC")))
+
+;; Accept an address register operand.
+
+(define_predicate "address_register_operand"
+ (and (match_code "reg")
+ (match_test "ADDRESS_REG_P (op)")))
More information about the Gcc-patches
mailing list