Skip to content

Commit

Permalink
xtensa: Fix the issue in "*extzvsi-1bit_addsubx"
Browse files Browse the repository at this point in the history
The second source register of insn "*extzvsi-1bit_addsubx" cannot be the
same as the destination register, because that register will be overwritten
with an intermediate value after insn splitting.

     /* example #1 */
     int test1(int b, int a) {
       return ((a & 1024) ? 4 : 0) + b;
     }

     ;; result #1 (incorrect)
     test1:
     	extui	a2, a3, 10, 1	;; overwrites A2 before used
     	addx4	a2, a2, a2
     	ret.n

This patch fixes that.

     ;; result #1 (correct)
     test1:
     	extui	a3, a3, 10, 1	;; uses A3 and then overwrites
     	addx4	a2, a3, a2
     	ret.n

However, it should be noted that the first source register can be the same
as the destination without any problems.

     /* example #2 */
     int test2(int a, int b) {
       return ((a & 1024) ? 4 : 0) + b;
     }

     ;; result (correct)
     test2:
     	extui	a2, a2, 10, 1	;; uses A2 and then overwrites
     	addx4	a2, a2, a3
     	ret.n

gcc/ChangeLog:

	* config/xtensa/xtensa.md (*extzvsi-1bit_addsubx):
	Add '&' to the destination register constraint to indicate that
	it is 'earlyclobber', append '0' to the first source register
	constraint to indicate that it can be the same as the destination
	register, and change the split condition from 1 to reload_completed
	so that the insn will be split only after RA in order to obtain
         allocated registers that satisfy the above constraints.
  • Loading branch information
jjsuwa-sys3175 authored and jcmvbkbc committed Nov 10, 2024
1 parent d7ef7d1 commit 45a45df
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions gcc/config/xtensa/xtensa.md
Original file line number Diff line number Diff line change
Expand Up @@ -1109,17 +1109,17 @@
(const_int 6)))])

(define_insn_and_split "*extzvsi-1bit_addsubx"
[(set (match_operand:SI 0 "register_operand" "=a")
[(set (match_operand:SI 0 "register_operand" "=&a")
(match_operator:SI 5 "addsub_operator"
[(and:SI (match_operator:SI 6 "logical_shift_operator"
[(match_operand:SI 1 "register_operand" "r")
[(match_operand:SI 1 "register_operand" "r0")
(match_operand:SI 3 "const_int_operand" "i")])
(match_operand:SI 4 "const_int_operand" "i"))
(match_operand:SI 2 "register_operand" "r")]))]
"TARGET_ADDX
&& IN_RANGE (exact_log2 (INTVAL (operands[4])), 1, 3)"
"#"
"&& 1"
"&& reload_completed"
[(set (match_dup 0)
(zero_extract:SI (match_dup 1)
(const_int 1)
Expand Down

0 comments on commit 45a45df

Please sign in to comment.