]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
dse: Use SUBREG_REG for copy_to_mode_reg in DSE replace_read for WORD_REGISTER_OPERAT...
authorJakub Jelinek <jakub@redhat.com>
Wed, 19 Apr 2023 09:13:11 +0000 (11:13 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 19 Apr 2023 09:13:11 +0000 (11:13 +0200)
While we've agreed this is not the right fix for the PR109040 bug,
the patch clearly improves generated code (at least on the testcase from the
PR), so I'd like to propose this as optimization heuristics improvement
for GCC 14.

2023-04-19  Jakub Jelinek  <jakub@redhat.com>

PR target/109040
* dse.cc (replace_read): If read_reg is a SUBREG of a word mode
REG, for WORD_REGISTER_OPERATIONS copy SUBREG_REG of it into
a new REG rather than the SUBREG.

gcc/dse.cc

index a2db8d1cc32fef430db11db2b0c4821d8b6183fc..802b949cfb2523d6cb389f64c88ec7cbfa6606c8 100644 (file)
@@ -2012,7 +2012,19 @@ replace_read (store_info *store_info, insn_info_t store_insn,
     }
   /* Force the value into a new register so that it won't be clobbered
      between the store and the load.  */
-  read_reg = copy_to_mode_reg (read_mode, read_reg);
+  if (WORD_REGISTER_OPERATIONS
+      && GET_CODE (read_reg) == SUBREG
+      && REG_P (SUBREG_REG (read_reg))
+      && GET_MODE (SUBREG_REG (read_reg)) == word_mode)
+    {
+      /* For WORD_REGISTER_OPERATIONS with subreg of word_mode register
+        force SUBREG_REG into a new register rather than the SUBREG.  */
+      rtx r = copy_to_mode_reg (word_mode, SUBREG_REG (read_reg));
+      read_reg = shallow_copy_rtx (read_reg);
+      SUBREG_REG (read_reg) = r;
+    }
+  else
+    read_reg = copy_to_mode_reg (read_mode, read_reg);
   insns = get_insns ();
   end_sequence ();