]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Convert LEA stack adjust insn to SUB when FLAGS_REG is dead
authorUros Bizjak <ubizjak@gmail.com>
Tue, 24 Jun 2025 09:02:02 +0000 (11:02 +0200)
committerUros Bizjak <ubizjak@gmail.com>
Tue, 24 Jun 2025 16:48:04 +0000 (18:48 +0200)
ADD/SUB is faster than LEA for most processors. Also, there are
several peephole2 patterns available that convert prologue esp
subtractions to pushes (at the end of i386.md). These process only
patterns with flags reg clobber, so they are ineffective
with clobber-less stack ptr adjustments, introduced by r16-1551
("x86: Enable separate shrink wrapping").

Introduce a peephole2 pattern that adds a clobber to a clobber-less
stack ptr adjustments when FLAGS_REG is dead.

gcc/ChangeLog:

* config/i386/i386.md
(@pro_epilogue_adjust_stack_add_nocc<mode>): Add type attribute.
(pro_epilogue_adjust_stack_add_nocc peephole2 pattern):
Convert pro_epilogue_adjust_stack_add_nocc variant to
pro_epilogue_adjust_stack_add when FLAGS_REG is dead.

gcc/config/i386/i386.md

index 423ef48e518f18a33878e52231b6779163f027a3..41a86544bbf7c91a43dbd3adc1166a3bc52e1ca8 100644 (file)
        (cond [(and (eq_attr "alternative" "0")
                    (not (match_test "TARGET_OPT_AGU")))
                 (const_string "alu")
-              (match_operand:<MODE> 2 "const0_operand")
+              (match_operand 2 "const0_operand")
                 (const_string "imov")
              ]
              (const_string "lea")))
    (clobber (mem:BLK (scratch)))]
   ""
 {
-  if (operands[2] == CONST0_RTX (<MODE>mode))
+  if (get_attr_type (insn) == TYPE_IMOV)
     return "mov{<imodesuffix>}\t{%1, %0|%0, %1}";
   else
     {
       return "lea{<imodesuffix>}\t{%E2, %0|%0, %E2}";
     }
 }
-  [(set (attr "length_immediate")
+  [(set (attr "type")
+       (cond [(match_operand 2 "const0_operand")
+                (const_string "imov")
+             ]
+             (const_string "lea")))
+   (set (attr "length_immediate")
        (cond [(eq_attr "type" "imov")
                 (const_string "0")
              ]
              (const_string "*")))
    (set_attr "mode" "<MODE>")])
 
+(define_peephole2
+  [(parallel
+     [(set (match_operand:P 0 "register_operand")
+          (plus:P (match_dup 0)
+                  (match_operand:P 1 "<nonmemory_operand>")))
+      (clobber (mem:BLK (scratch)))])]
+  "peep2_regno_dead_p (0, FLAGS_REG)"
+  [(parallel
+     [(set (match_dup 0)
+          (plus:P (match_dup 0) (match_dup 1)))
+      (clobber (reg:CC FLAGS_REG))
+      (clobber (mem:BLK (scratch)))])])
+
 (define_insn "@pro_epilogue_adjust_stack_sub_<mode>"
   [(set (match_operand:P 0 "register_operand" "=r")
        (minus:P (match_operand:P 1 "register_operand" "0")