@@ -2933,6 +2933,38 @@ bool GCNHazardRecognizer::ShouldPreferAnother(SUnit *SU) {
2933
2933
return false ;
2934
2934
}
2935
2935
2936
+ // Adjust global offsets for instructions bundled with S_GETPC_B64 after
2937
+ // insertion of a new instruction.
2938
+ static void updateGetPCBundle (MachineInstr *NewMI) {
2939
+ if (!NewMI->isBundled ())
2940
+ return ;
2941
+
2942
+ // Find start of bundle.
2943
+ auto I = NewMI->getIterator ();
2944
+ while (I->isBundledWithPred ())
2945
+ I--;
2946
+ if (I->isBundle ())
2947
+ I++;
2948
+
2949
+ // Bail if this is not an S_GETPC bundle.
2950
+ if (I->getOpcode () != AMDGPU::S_GETPC_B64)
2951
+ return ;
2952
+
2953
+ // Update offsets of any references in the bundle.
2954
+ const unsigned NewBytes = 4 ;
2955
+ assert (NewMI->getOpcode () == AMDGPU::S_WAITCNT_DEPCTR &&
2956
+ " Unexpected instruction insertion in bundle" );
2957
+ auto NextMI = std::next (NewMI->getIterator ());
2958
+ auto End = NewMI->getParent ()->end ();
2959
+ while (NextMI != End && NextMI->isBundledWithPred ()) {
2960
+ for (auto &Operand : NextMI->operands ()) {
2961
+ if (Operand.isGlobal ())
2962
+ Operand.setOffset (Operand.getOffset () + NewBytes);
2963
+ }
2964
+ NextMI++;
2965
+ }
2966
+ }
2967
+
2936
2968
bool GCNHazardRecognizer::fixVALUMaskWriteHazard (MachineInstr *MI) {
2937
2969
if (!ST.hasVALUMaskWriteHazard ())
2938
2970
return false ;
@@ -3050,22 +3082,12 @@ bool GCNHazardRecognizer::fixVALUMaskWriteHazard(MachineInstr *MI) {
3050
3082
auto NextMI = std::next (MI->getIterator ());
3051
3083
3052
3084
// Add s_waitcnt_depctr sa_sdst(0) after SALU write.
3053
- BuildMI (*MI->getParent (), NextMI, MI->getDebugLoc (),
3054
- TII.get (AMDGPU::S_WAITCNT_DEPCTR))
3055
- .addImm (AMDGPU::DepCtr::encodeFieldSaSdst (0 ));
3085
+ auto NewMI = BuildMI (*MI->getParent (), NextMI, MI->getDebugLoc (),
3086
+ TII.get (AMDGPU::S_WAITCNT_DEPCTR))
3087
+ .addImm (AMDGPU::DepCtr::encodeFieldSaSdst (0 ));
3056
3088
3057
3089
// SALU write may be s_getpc in a bundle.
3058
- if (MI->getOpcode () == AMDGPU::S_GETPC_B64) {
3059
- // Update offsets of any references in the bundle.
3060
- while (NextMI != MI->getParent ()->end () &&
3061
- NextMI->isBundledWithPred ()) {
3062
- for (auto &Operand : NextMI->operands ()) {
3063
- if (Operand.isGlobal ())
3064
- Operand.setOffset (Operand.getOffset () + 4 );
3065
- }
3066
- NextMI++;
3067
- }
3068
- }
3090
+ updateGetPCBundle (NewMI);
3069
3091
3070
3092
return true ;
3071
3093
}
0 commit comments