Skip to content

Commit 01089cc

Browse files
author
rearnsha
committed
[arm] Implement negscc using SBC when appropriate.
When the carry flag is appropriately set by a comprison, negscc patterns can expand into a simple SBC of a register with itself. This means we can convert two conditional instructions into a single non-conditional instruction. Furthermore, in Thumb2 we can avoid the need for an IT instruction as well. This patch also fixes the remaining testcase that we initially XFAILed in the first patch of this series. gcc: * config/arm/arm.md (negscc_borrow): New pattern. (mov_negscc): Don't split if the insn would match negscc_borrow. * config/arm/thumb2.md (thumb2_mov_negscc): Likewise. (thumb2_mov_negscc_strict_it): Likewise. testsuite: * gcc.target/arm/negdi-3.c: Remove XFAIL markers. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@277175 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 7d9d197 commit 01089cc

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
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 (negscc_borrow): New pattern.
4+
(mov_negscc): Don't split if the insn would match negscc_borrow.
5+
* config/arm/thumb2.md (thumb2_mov_negscc): Likewise.
6+
(thumb2_mov_negscc_strict_it): Likewise.
7+
18
2019-10-18 Richard Earnshaw <[email protected]>
29

310
* config/arm/arm.c (arm_insn_cost): New function.

gcc/config/arm/arm.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6612,13 +6612,23 @@
66126612
(set_attr "type" "multiple")]
66136613
)
66146614

6615+
(define_insn "*negscc_borrow"
6616+
[(set (match_operand:SI 0 "s_register_operand" "=r")
6617+
(neg:SI (match_operand:SI 1 "arm_borrow_operation" "")))]
6618+
"TARGET_32BIT"
6619+
"sbc\\t%0, %0, %0"
6620+
[(set_attr "conds" "use")
6621+
(set_attr "length" "4")
6622+
(set_attr "type" "adc_reg")]
6623+
)
6624+
66156625
(define_insn_and_split "*mov_negscc"
66166626
[(set (match_operand:SI 0 "s_register_operand" "=r")
66176627
(neg:SI (match_operator:SI 1 "arm_comparison_operator_mode"
66186628
[(match_operand 2 "cc_register" "") (const_int 0)])))]
6619-
"TARGET_ARM"
6629+
"TARGET_ARM && !arm_borrow_operation (operands[1], SImode)"
66206630
"#" ; "mov%D1\\t%0, #0\;mvn%d1\\t%0, #0"
6621-
"TARGET_ARM"
6631+
"&& true"
66226632
[(set (match_dup 0)
66236633
(if_then_else:SI (match_dup 1)
66246634
(match_dup 3)

gcc/config/arm/thumb2.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@
368368
[(set (match_operand:SI 0 "s_register_operand" "=r")
369369
(neg:SI (match_operator:SI 1 "arm_comparison_operator_mode"
370370
[(match_operand 2 "cc_register" "") (const_int 0)])))]
371-
"TARGET_THUMB2 && !arm_restrict_it"
371+
"TARGET_THUMB2
372+
&& !arm_restrict_it
373+
&& !arm_borrow_operation (operands[1], SImode)"
372374
"#" ; "ite\\t%D1\;mov%D1\\t%0, #0\;mvn%d1\\t%0, #0"
373375
"&& true"
374376
[(set (match_dup 0)
@@ -387,7 +389,9 @@
387389
[(set (match_operand:SI 0 "low_register_operand" "=l")
388390
(neg:SI (match_operator:SI 1 "arm_comparison_operator_mode"
389391
[(match_operand 2 "cc_register" "") (const_int 0)])))]
390-
"TARGET_THUMB2 && arm_restrict_it"
392+
"TARGET_THUMB2
393+
&& arm_restrict_it
394+
&& !arm_borrow_operation (operands[1], SImode)"
391395
"#" ; ";mvn\\t%0, #0 ;it\\t%D1\;mov%D1\\t%0, #0\"
392396
"&& reload_completed"
393397
[(set (match_dup 0)

gcc/testsuite/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2019-10-18 Richard Earnshaw <[email protected]>
2+
3+
* gcc.target/arm/negdi-3.c: Remove XFAIL markers.
4+
15
2019-10-18 Richard Earnshaw <[email protected]>
26

37
* gcc.target/arm/pr53447-1.c: Remove XFAIL.

gcc/testsuite/gcc.target/arm/negdi-3.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Expected output:
1111
rsbs r0, r0, #0
1212
sbc r1, r1, r1
1313
*/
14-
/* { dg-final { scan-assembler-times "rsb" 1 { xfail *-*-* } } } */
15-
/* { dg-final { scan-assembler-times "sbc" 1 { xfail *-*-* } } } */
16-
/* { dg-final { scan-assembler-times "mov" 0 { xfail *-*-* } } } */
17-
/* { dg-final { scan-assembler-times "rsc" 0 { xfail *-*-* } } } */
14+
/* { dg-final { scan-assembler-times "rsb" 1 } } */
15+
/* { dg-final { scan-assembler-times "sbc" 1 } } */
16+
/* { dg-final { scan-assembler-times "mov" 0 } } */
17+
/* { dg-final { scan-assembler-times "rsc" 0 } } */

0 commit comments

Comments
 (0)