On Dec 10, 2025, Uros Bizjak <[email protected]> wrote:

> OK. There are probably more pairs involving insns w/ and w/o clobber,
> but I guess the ones you add are the most relevant.

Presumably you meant patterns other than the lea ones, because the
following ones, removing clobbers from the first insn of the pair,
didn't yield any hits on x86_64- or i686-linux-gnu bootstraps.  The
bootstraps were successful nevertheless (with and without
"gcc_unreachable ();" preparation statements), and I regression-tested
them (along with other patches, without the preparation statements) as
well, so if you think there'd be any use for them, I'd be happy to
contribute a commit message and ChangeLog entry along with them.

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 7eafdf9ec1b6d..139cddaa41162 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -6494,6 +6494,58 @@ (define_peephole2
   [(set (match_dup 3) (plus:SWI48 (plus:SWI48 (match_dup 0)
                                              (match_dup 1))
                                  (match_dup 2)))])
+
+(define_peephole2
+  [(set (match_operand:SWI48 0 "register_operand")
+       (plus:SWI48 (match_dup 0)
+                   (match_operand 1 "register_operand")))
+   (parallel [(set (match_dup 0)
+                  (plus:SWI48 (match_dup 0)
+                              (match_operand 2 "x86_64_immediate_operand")))
+             (clobber (reg:CC FLAGS_REG))])]
+  "!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun)"
+  [(set (match_dup 0) (plus:SWI48 (plus:SWI48 (match_dup 0)
+                                             (match_dup 1))
+                                 (match_dup 2)))])
+
+(define_peephole2
+  [(set (match_operand:SWI48 0 "register_operand")
+       (plus:SWI48 (match_dup 0)
+                   (match_operand 1 "register_operand")))
+   (set (match_dup 0)
+       (plus:SWI48 (match_dup 0)
+                   (match_operand 2 "x86_64_immediate_operand")))]
+  "!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun)"
+  [(set (match_dup 0) (plus:SWI48 (plus:SWI48 (match_dup 0)
+                                             (match_dup 1))
+                                 (match_dup 2)))])
+
+(define_peephole2
+  [(set (match_operand:SWI48 0 "register_operand")
+       (plus:SWI48 (match_dup 0)
+                   (match_operand 1 "register_operand")))
+   (parallel [(set (match_operand:SWI48 3 "register_operand")
+                  (plus:SWI48 (match_dup 0)
+                              (match_operand 2 "x86_64_immediate_operand")))
+             (clobber (reg:CC FLAGS_REG))])]
+  "(!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun))
+   && peep2_reg_dead_p (2, operands[0])"
+  [(set (match_dup 3) (plus:SWI48 (plus:SWI48 (match_dup 0)
+                                             (match_dup 1))
+                                 (match_dup 2)))])
+
+(define_peephole2
+  [(set (match_operand:SWI48 0 "register_operand")
+       (plus:SWI48 (match_dup 0)
+                   (match_operand 1 "register_operand")))
+   (set (match_operand:SWI48 3 "register_operand")
+       (plus:SWI48 (match_dup 0)
+                   (match_operand 2 "x86_64_immediate_operand")))]
+  "(!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun))
+   && peep2_reg_dead_p (2, operands[0])"
+  [(set (match_dup 3) (plus:SWI48 (plus:SWI48 (match_dup 0)
+                                             (match_dup 1))
+                                 (match_dup 2)))])
 
 ;; Add instructions
 


-- 
Alexandre Oliva, happy hacker            https://blog.lx.oliva.nom.br/
Free Software Activist     FSFLA co-founder     GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity.
Excluding neuro-others for not behaving ""normal"" is *not* inclusive!

Reply via email to