Skip to content

Commit 8aefed8

Browse files
author
rearnsha
committed
[arm] Allow the summation result of signed add-with-overflow to be discarded.
This patch matches the signed add-with-overflow patterns when the summation itself is dropped. In this case we can use CMN (or CMP with some immediates). There are a small number of constants in thumb2 where this can result in less dense code (as we lack 16-bit CMN with immediate patterns). To handle this we use peepholes to try these alternatives when either a scratch is available (0 <= i <= 7) or the original register is dead (0 <= i <= 255). We don't use a scratch in the pattern as if those conditions are not satisfied then the 32-bit form is preferable to forcing a reload. * config/arm/arm.md (addsi3_compareV_reg_nosum): New insn. (addsi3_compareV_imm_nosum): New insn. Also add peephole2 patterns to transform this back into the summation version when that leads to smaller code. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@277185 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent d302ef3 commit 8aefed8

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

gcc/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2019-10-18 Richard Earnshaw <[email protected]>
2+
3+
* config/arm/arm.md (addsi3_compareV_reg_nosum): New insn.
4+
(addsi3_compareV_imm_nosum): New insn. Also add peephole2 patterns
5+
to transform this back into the summation version when that leads
6+
to smaller code.
7+
18
2019-10-18 Richard Earnshaw <[email protected]>
29

310
* config/arm/arm.md (addv<mode>4): Delete.

gcc/config/arm/arm.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,21 @@
803803
(set_attr "type" "alus_sreg")]
804804
)
805805

806+
(define_insn "*addsi3_compareV_reg_nosum"
807+
[(set (reg:CC_V CC_REGNUM)
808+
(compare:CC_V
809+
(plus:DI
810+
(sign_extend:DI (match_operand:SI 0 "register_operand" "%l,r"))
811+
(sign_extend:DI (match_operand:SI 1 "register_operand" "l,r")))
812+
(sign_extend:DI (plus:SI (match_dup 0) (match_dup 1)))))]
813+
"TARGET_32BIT"
814+
"cmn%?\\t%0, %1"
815+
[(set_attr "conds" "set")
816+
(set_attr "arch" "t2,*")
817+
(set_attr "length" "2,4")
818+
(set_attr "type" "alus_sreg")]
819+
)
820+
806821
(define_insn "addsi3_compareV_imm"
807822
[(set (reg:CC_V CC_REGNUM)
808823
(compare:CC_V
@@ -828,6 +843,69 @@
828843
(set_attr "type" "alus_imm")]
829844
)
830845

846+
(define_insn "addsi3_compareV_imm_nosum"
847+
[(set (reg:CC_V CC_REGNUM)
848+
(compare:CC_V
849+
(plus:DI
850+
(sign_extend:DI
851+
(match_operand:SI 0 "register_operand" "l,r,r"))
852+
(match_operand 1 "arm_addimm_operand" "Pw,I,L"))
853+
(sign_extend:DI (plus:SI (match_dup 0) (match_dup 1)))))]
854+
"TARGET_32BIT
855+
&& INTVAL (operands[1]) == ARM_SIGN_EXTEND (INTVAL (operands[1]))"
856+
"@
857+
cmp%?\\t%0, #%n1
858+
cmn%?\\t%0, %1
859+
cmp%?\\t%0, #%n1"
860+
[(set_attr "conds" "set")
861+
(set_attr "arch" "t2,*,*")
862+
(set_attr "length" "2,4,4")
863+
(set_attr "type" "alus_imm")]
864+
)
865+
866+
;; We can handle more constants efficently if we can clobber either a scratch
867+
;; or the other source operand. We deliberately leave this late as in
868+
;; high register pressure situations it's not worth forcing any reloads.
869+
(define_peephole2
870+
[(match_scratch:SI 2 "l")
871+
(set (reg:CC_V CC_REGNUM)
872+
(compare:CC_V
873+
(plus:DI
874+
(sign_extend:DI
875+
(match_operand:SI 0 "low_register_operand"))
876+
(match_operand 1 "const_int_operand"))
877+
(sign_extend:DI (plus:SI (match_dup 0) (match_dup 1)))))]
878+
"TARGET_THUMB2
879+
&& satisfies_constraint_Pd (operands[1])"
880+
[(parallel[
881+
(set (reg:CC_V CC_REGNUM)
882+
(compare:CC_V
883+
(plus:DI (sign_extend:DI (match_dup 0))
884+
(sign_extend:DI (match_dup 1)))
885+
(sign_extend:DI (plus:SI (match_dup 0) (match_dup 1)))))
886+
(set (match_dup 2) (plus:SI (match_dup 0) (match_dup 1)))])]
887+
)
888+
889+
(define_peephole2
890+
[(set (reg:CC_V CC_REGNUM)
891+
(compare:CC_V
892+
(plus:DI
893+
(sign_extend:DI
894+
(match_operand:SI 0 "low_register_operand"))
895+
(match_operand 1 "const_int_operand"))
896+
(sign_extend:DI (plus:SI (match_dup 0) (match_dup 1)))))]
897+
"TARGET_THUMB2
898+
&& dead_or_set_p (peep2_next_insn (0), operands[0])
899+
&& satisfies_constraint_Py (operands[1])"
900+
[(parallel[
901+
(set (reg:CC_V CC_REGNUM)
902+
(compare:CC_V
903+
(plus:DI (sign_extend:DI (match_dup 0))
904+
(sign_extend:DI (match_dup 1)))
905+
(sign_extend:DI (plus:SI (match_dup 0) (match_dup 1)))))
906+
(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))])]
907+
)
908+
831909
(define_insn "addsi3_compare0"
832910
[(set (reg:CC_NOOV CC_REGNUM)
833911
(compare:CC_NOOV

0 commit comments

Comments
 (0)