]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
AVR: Run pass avr-fuse-add a second time after pass_cprop_hardreg.
authorGeorg-Johann Lay <avr@gjlay.de>
Fri, 30 Aug 2024 17:38:30 +0000 (19:38 +0200)
committerGeorg-Johann Lay <avr@gjlay.de>
Sat, 31 Aug 2024 18:30:40 +0000 (20:30 +0200)
gcc/
* config/avr/avr-passes.cc (avr_pass_fuse_add) <clone>: Override.
* config/avr/avr-passes.def (avr_pass_fuse_add): Run again
after pass_cprop_hardreg.

gcc/config/avr/avr-passes.cc
gcc/config/avr/avr-passes.def

index 58b132b64bec7291e242f2541c72d196f8e38651..8a71b57ada104ca2cc893de1ff39ef493456f8d5 100644 (file)
@@ -1026,6 +1026,13 @@ public:
     this->name = name;
   }
 
+  // Cloning is required because we are running one instance of the pass
+  // before peephole2. and a second one after cprop_hardreg.
+  opt_pass * clone () final override
+  {
+    return make_avr_pass_fuse_add (m_ctxt);
+  }
+
   bool gate (function *) final override
   {
     return optimize && avr_fuse_add > 0;
index 3be82e0271010103923e7ee2cd9cc99e5456f72f..cd89d67372765d421928ca8e0f85d6bcec8fe37c 100644 (file)
 
 INSERT_PASS_BEFORE (pass_peephole2, 1, avr_pass_fuse_add);
 
+/* There are cases where avr-fuse-add doesn't find POST_INC cases because
+   the RTL code at that time is too long-winded, and moves registers back and
+   forth (which seems to be the same reason for why pass auto_inc_dec cannot
+   find POST_INC, either).  Some of that long-windedness is cleaned up very
+   late in pass cprop_hardreg, which opens up new opportunities to find post
+   increments.  An example is the following function from AVR-LibC's qsort:
+
+   void swapfunc (char *a, char *b, int n)
+   {
+       do
+       {
+           char tmp = *a;
+           *a++ = *b;
+           *b++ = tmp;
+       } while (--n > 0);
+   }
+
+   Hence, run avr-fuse-add twice; the second time after cprop_hardreg.  */
+
+INSERT_PASS_AFTER (pass_cprop_hardreg, 1, avr_pass_fuse_add);
+
 /* An analysis pass that runs prior to prologue / epilogue generation.
    Computes cfun->machine->gasisr.maybe which is used in prologue and
    epilogue generation provided -mgas-isr-prologues is on.  */