Whee, more fallout from the cselib work. This is clearly another backend bug.
The H8 port has this peephole: ;; Turn ;; ;; mov.l er7,er0 ;; add.l #10,er0 (takes 8 bytes) ;; ;; into ;; ;; sub.l er0,er0 ;; add.b #10,r0l ;; add.l er7,er0 (takes 6 bytes) (define_peephole2 [(set (match_operand:SI 0 "register_operand" "") (match_operand:SI 1 "register_operand" "")) (set (match_dup 0) (plus:SI (match_dup 0) (match_operand:SI 2 "const_int_operand" "")))] "(TARGET_H8300H || TARGET_H8300S) && REG_P (operands[0]) && REG_P (operands[1]) && REGNO (operands[0]) != REGNO (operands[1]) && !satisfies_constraint_L (operands[2]) && !satisfies_constraint_N (operands[2]) && ((INTVAL (operands[2]) & 0xff) == INTVAL (operands[2]) || (INTVAL (operands[2]) & 0xff00) == INTVAL (operands[2]) || INTVAL (operands[2]) == 0xffff || INTVAL (operands[2]) == 0xfffe)" [(set (match_dup 0) (match_dup 2)) (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))] "") As the comment indicates this saves a couple bytes of space. But boy it's a bad idea if operand0 is the stack pointer. Aside from ICE related to ARG_SIZE notes, imagine what happens if you take an interrupt after zero-ing $sp, but before the final add.l. Nothing good. The fix is pretty simple, verify operands[0] is not the stack pointer. I looked briefly at the other peepholes, but none of the others seem to be fundamentally broken when a destination is the stack pointer. The ICE showed up in a good variety of existing tests. So there's no new test. Committing to the trunk. Jeff
commit 14162197fd4cf0e3a848d32bd9385876e1b1f249 Author: Jeff Law <l...@redhat.com> Date: Tue Apr 7 17:55:00 2020 -0600 Fix a variety of testsuite failures on the H8 after recent cselib changes PR rtl-optimization/92264 * config/h8300/h8300.md (mov;add peephole2): Avoid applying when the destination is the stack pointer. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 12803e90b0a..6f2dcfb766c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2020-04-07 Jeff Law <l...@redhat.com> + + PR rtl-optimization/92264 + * config/h8300/h8300.md (mov;add peephole2): Avoid applying when + the destination is the stack pointer. + 2020-04-07 Jakub Jelinek <ja...@redhat.com> PR rtl-optimization/94291 diff --git a/gcc/config/h8300/h8300.md b/gcc/config/h8300/h8300.md index bcc78a4ce4d..fdd2d8b02d7 100644 --- a/gcc/config/h8300/h8300.md +++ b/gcc/config/h8300/h8300.md @@ -4299,6 +4299,7 @@ (plus:SI (match_dup 0) (match_operand:SI 2 "const_int_operand" "")))] "(TARGET_H8300H || TARGET_H8300S) + && operands[0] != stack_pointer_rtx && REG_P (operands[0]) && REG_P (operands[1]) && REGNO (operands[0]) != REGNO (operands[1]) && !satisfies_constraint_L (operands[2])