I am running into a problem when I turn on post-RA scheduler with mode "ANTIDEP_CRITICAL" for mips.<br>I'd appreciate if someone could explain what is going wrong here.<br><br>This is the basic block before post RA scheduling (at PostRASchedulerList.cpp:322):<br>

<br><b>(gdb)<br>
#3  0x0000000000ed3d26 in runOnMachineFunction (this=0x20aa470, Fn=...)<br>
    at lib/CodeGen/PostRASchedulerList.cpp:322<br>
322            Scheduler.Observe(MI, CurrentCount);<br><br>(gdb) p (*MBB).dump()</b>
<b><br>
BB#218: derived from LLVM BB %if.then1289<br>
    Live Ins: %A2 %S0_64 %S1_64 %S2_64 %S4 %S5_64 %T0 %T1 %T2 %T3_64 %T6
 %T8 %T9<br>
    Predecessors according to CFG: BB#217<br>    ...<br>
    %V0<def> = ADDu %ZERO, %T9<kill><br>
    %T9_64<def> = LD_P8 %T3_64, <ga:@intrapred>[TF=3]; 
mem:LD8[GOT]<br>
    ...<br>
    JALR64 %T9_64<kill>, %A0_64<kill>, %A1<kill>, 
%A2<kill>, %A3<kill>, %T0<kill>, <regmask>, 
%SP<imp-def>, %V0<imp-def><br>
    ...<br>
    BNE %V0, %V1, <BB#372><br><br></b>
MI is JALR64 which is a call (jump-and-link-register). T9_64 is the destination register and A0 - A3 and T0 are the argument registers. <br>These registers are not callee-saved.<br><br><b>(gdb) p MI->dump()<br>
  JALR64 %T9_64<kill>, %A0_64<kill>, %A1<kill>, 
%A2<kill>, %A3<kill>, %T0<kill>, <regmask>, 
%SP<imp-def>, %V0<imp-def><br></b>
<br><br>After the region above the JALR64 instruction is scheduled, the basic block looks like this (at PostRASchedulerList.cpp:341): <br><br><b>(gdb) <br>341        Scheduler.FixupKills(MBB);<br>(gdb) p (*MBB).dump()<br>

BB#218:

 derived from LLVM BB %if.then1289<br>    Live Ins: %A2 %S0_64 %S1_64 
%S2_64 %S4 %S5_64 %T0 %T1 %T2 %T3_64 %T6 %T8 %T9<br>
    Predecessors according to CFG: BB#217<br>    %S6_64<def> = 
LD_P8 %T3_64, <ga:@intrapred>[TF=3]; mem:LD8[GOT]<br>    
%V0<def> = ADDu %ZERO, %T9<kill><br>    ...<br>    JALR64 
%S6_64<kill>, %A0_64<kill>, %A1<kill>, 
%A2<kill>, %A3<kill>, %T0<kill>, <regmask>, 
%SP<imp-def>, %V0<imp-def><br>
    ...<br>$110 = void<br></b><br>CriticalAntiDepBreaker has replaced T9_64 with S6_64 to break an 
anti-dependence edge.<br>This code is incorrect since the first operand of 
JALR64 has to be T9_64 in PIC mode. <br><br>After further investigation, I found that the flag for T9_64 of CriticalAntiDepBreaker::KeepRegs that had been set in PrescanInstruction was reset in ScanInstruction, which I think is causing the problem:<br>

<br>
<b>CriticalAntiDepBreaker.cpp:<br>
00154   PrescanInstruction(MI);<br>00155   ScanInstruction(MI, Count);<br><br></b>T9_64 is cleared in CriticalAntiDepBreaker.cpp:264:<br><br><b>Breakpoint 8, llvm::CriticalAntiDepBreaker::ScanInstruction (this=0x262d290, <br>

    MI=0x22b2168, Count=15)<br>    at lib/CodeGen/CriticalAntiDepBreaker.cpp:264<br>264                KeepRegs.reset(i);<br>(gdb) p i<br>$179 = 145<br>(gdb) p /x KeepRegs.test(145)<br>$180 = 0x1<br></b><br>145 is the value of T9_64.<br>

<br>In CriticalAntiDepBreaker.cpp, there is a comment " Also assume all registers used in a call must not be changed (ABI).", but T9_64 is changed here. Also it says "registers that are 
defed but not used in this 
instruction are now dead", but I don't see the code that checks whether T9_64 is used.<br><br>