diff mbox series

[avr] Add an RTL peephole to tweak lower_reg:QI o= cst.

Message ID 656470b7-b83a-4fc7-b3cf-b27364cb78a9@gjlay.de
State New
Headers show
Series [avr] Add an RTL peephole to tweak lower_reg:QI o= cst. | expand

Commit Message

Georg-Johann Lay Nov. 6, 2024, 8:58 a.m. UTC
For operations like  X o= CST, regalloc may spill l-reg X to a d-reg:
    D =  X
    D o= CST
    X =  D
where it is better to instead
    D =  CST
    X o= D
This patch adds an according RTL peephole.

Ok for trunk?

Johann

--

AVR: Add an RTL peephole to tweak lower_reg:QI o= cst.

For operations like  X o= CST, regalloc may spill l-reg X to a d-reg:
    D =  X
    D o= CST
    X =  D
where it is better to instead
    D =  CST
    X o= D
This patch adds an according RTL peephole.

gcc/
	* config/avr/avr.md: Add a peephole2 that improves bit operations
	with a lower register and a constant.

Comments

Denis Chertykov Nov. 6, 2024, 10:25 a.m. UTC | #1
ср, 6 нояб. 2024 г. в 12:58, Georg-Johann Lay <avr@gjlay.de>:
>
> For operations like  X o= CST, regalloc may spill l-reg X to a d-reg:
>     D =  X
>     D o= CST
>     X =  D
> where it is better to instead
>     D =  CST
>     X o= D
> This patch adds an according RTL peephole.
>
> Ok for trunk?

Please apply.

Denis.

>
> Johann
>
> --
>
> AVR: Add an RTL peephole to tweak lower_reg:QI o= cst.
>
> For operations like  X o= CST, regalloc may spill l-reg X to a d-reg:
>     D =  X
>     D o= CST
>     X =  D
> where it is better to instead
>     D =  CST
>     X o= D
> This patch adds an according RTL peephole.
>
> gcc/
>         * config/avr/avr.md: Add a peephole2 that improves bit operations
>         with a lower register and a constant.
>
diff mbox series

Patch

AVR: Add an RTL peephole to tweak lower_reg:QI o= cst.

For operations like  X o= CST, regalloc may spill l-reg X to a d-reg:
   D =  X
   D o= CST
   X =  D
where it is better to instead
   D =  CST
   X o= D
This patch adds an according RTL peephole.

gcc/
	* config/avr/avr.md: Add a peephole2 that improves bit operations
	with a lower register and a constant.

diff --git a/gcc/config/avr/avr.md b/gcc/config/avr/avr.md
index 28ade560ff4..f8544fb8dfa 100644
--- a/gcc/config/avr/avr.md
+++ b/gcc/config/avr/avr.md
@@ -4766,6 +4766,37 @@  (define_peephole2
               (clobber (reg:CC REG_CC))])])
 
 
+;; For operations like  X o= CST, regalloc may spill l-reg X to a d-reg:
+;;    D =  X
+;;    D o= CST
+;;    X =  D
+;; where it is better to instead
+;;    D =  CST
+;;    X o= D
+(define_peephole2
+  [; Move l-reg to d-reg for the purpose of BITOP.
+   (parallel [(set (match_operand:ALL1 0 "d_register_operand")
+                   (match_operand:ALL1 1 "l_register_operand"))
+              (clobber (reg:CC REG_CC))])
+   (parallel [(set (match_dup 0)
+                   (bitop:ALL1 (match_dup 0)
+                               (match_operand:ALL1 2 "const_operand")))
+              (clobber (reg:CC REG_CC))])
+   ; Move d-reg result back to l-reg.
+   (parallel [(set (match_dup 1)
+                   (match_dup 0))
+              (clobber (reg:CC REG_CC))])]
+  "peep2_reg_dead_p (3, operands[0])"
+  [; "movqi_insn"
+   (parallel [(set (match_dup 0)
+                   (match_dup 2))
+              (clobber (reg:CC REG_CC))])
+   (parallel [(set (match_dup 1)
+                   (bitop:ALL1 (match_dup 1)
+                               (match_dup 0)))
+              (clobber (reg:CC REG_CC))])])
+
+
 ;; swap swap swap swap swap swap swap swap swap swap swap swap swap swap swap
 ;; swap