[llvm] 8544ce8 - [AVR] Set R31R30 as clobbered after ADJCALLSTACKDOWN

Ayke van Laethem via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 24 05:03:38 PDT 2021


Author: Ayke van Laethem
Date: 2021-07-24T14:03:26+02:00
New Revision: 8544ce80f881a33a2c4c8e234709d136b52fa4d8

URL: https://github.com/llvm/llvm-project/commit/8544ce80f881a33a2c4c8e234709d136b52fa4d8
DIFF: https://github.com/llvm/llvm-project/commit/8544ce80f881a33a2c4c8e234709d136b52fa4d8.diff

LOG: [AVR] Set R31R30 as clobbered after ADJCALLSTACKDOWN

In most cases, using R31R30 is fine because the call (which always
precedes ADJCALLSTACKDOWN) will clobber R31R30 anyway. However, in some
rare cases the register allocator might insert an instruction between
the call and the ADJCALLSTACKDOWN instruction and expect the register
pair to be live afterwards. I think this happens as a result of
rematerialization. Therefore, to fix this, the instruction needs to have
Defs set to R31R30.

Setting the Defs field does have the effect of making the instruction
look dead, which it certainly is not. This is fixed by setting
hasSideEffects to true.

Differential Revision: https://reviews.llvm.org/D97745

Added: 
    

Modified: 
    llvm/lib/Target/AVR/AVRInstrInfo.td

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AVR/AVRInstrInfo.td b/llvm/lib/Target/AVR/AVRInstrInfo.td
index 5b3a67e0e765..fa1246e16ea3 100644
--- a/llvm/lib/Target/AVR/AVRInstrInfo.td
+++ b/llvm/lib/Target/AVR/AVRInstrInfo.td
@@ -360,11 +360,13 @@ Uses = [SP] in
                                 "#ADJCALLSTACKDOWN",
                                 [(AVRcallseq_start timm:$amt, timm:$amt2)]>;
 
-  // R31R30 is used to update SP, since it is a scratch reg and this instruction
-  // is placed after the function call then R31R30 should be always free.
-  //let Defs = [R31R30],
-  //Uses = [R31R30] in
-  //:TODO: if we enable this, the pseudo is killed because it looks dead
+  // R31R30 is used to update SP. It is normally free because it is a
+  // call-clobbered register but it is necessary to set it as a def as the
+  // register allocator might use it in rare cases (for rematerialization, it
+  // seems). hasSideEffects needs to be set to true so this instruction isn't
+  // considered dead.
+  let Defs = [R31R30],
+  hasSideEffects=1 in
   def ADJCALLSTACKUP : Pseudo<(outs),
                               (ins i16imm:$amt1, i16imm:$amt2),
                               "#ADJCALLSTACKUP",


        


More information about the llvm-commits mailing list