@@ -2930,9 +2930,9 @@ bool SIInstrInfo::findCommutedOpIndices(const MCInstrDesc &Desc,
29302930
29312931bool SIInstrInfo::isBranchOffsetInRange (unsigned BranchOp,
29322932 int64_t BrOffset) const {
2933- // BranchRelaxation should never have to check s_setpc_b64 because its dest
2934- // block is unanalyzable.
2935- assert (BranchOp != AMDGPU::S_SETPC_B64 );
2933+ // BranchRelaxation should never have to check s_setpc_b64 or s_add_pc_i64
2934+ // because its dest block is unanalyzable.
2935+ assert (isSOPP ( BranchOp) || isSOPK (BranchOp) );
29362936
29372937 // Convert to dwords.
29382938 BrOffset /= 4 ;
@@ -2973,13 +2973,30 @@ void SIInstrInfo::insertIndirectBranch(MachineBasicBlock &MBB,
29732973 MachineFunction *MF = MBB.getParent ();
29742974 MachineRegisterInfo &MRI = MF->getRegInfo ();
29752975 const SIMachineFunctionInfo *MFI = MF->getInfo <SIMachineFunctionInfo>();
2976+ auto I = MBB.end ();
2977+ auto &MCCtx = MF->getContext ();
2978+
2979+ if (ST.hasAddPC64Inst ()) {
2980+ MCSymbol *Offset =
2981+ MCCtx.createTempSymbol (" offset" , /* AlwaysAddSuffix=*/ true );
2982+ auto AddPC = BuildMI (MBB, I, DL, get (AMDGPU::S_ADD_PC_I64))
2983+ .addSym (Offset, MO_FAR_BRANCH_OFFSET);
2984+ MCSymbol *PostAddPCLabel =
2985+ MCCtx.createTempSymbol (" post_addpc" , /* AlwaysAddSuffix=*/ true );
2986+ AddPC->setPostInstrSymbol (*MF, PostAddPCLabel);
2987+ auto *OffsetExpr = MCBinaryExpr::createSub (
2988+ MCSymbolRefExpr::create (DestBB.getSymbol (), MCCtx),
2989+ MCSymbolRefExpr::create (PostAddPCLabel, MCCtx), MCCtx);
2990+ Offset->setVariableValue (OffsetExpr);
2991+ return ;
2992+ }
2993+
2994+ assert (RS && " RegScavenger required for long branching" );
29762995
29772996 // FIXME: Virtual register workaround for RegScavenger not working with empty
29782997 // blocks.
29792998 Register PCReg = MRI.createVirtualRegister (&AMDGPU::SReg_64RegClass);
29802999
2981- auto I = MBB.end ();
2982-
29833000 // Note: as this is used after hazard recognizer we need to apply some hazard
29843001 // workarounds directly.
29853002 const bool FlushSGPRWrites = (ST.isWave64 () && ST.hasVALUMaskWriteHazard ()) ||
@@ -2995,7 +3012,6 @@ void SIInstrInfo::insertIndirectBranch(MachineBasicBlock &MBB,
29953012 MachineInstr *GetPC = BuildMI (MBB, I, DL, get (AMDGPU::S_GETPC_B64), PCReg);
29963013 ApplyHazardWorkarounds ();
29973014
2998- auto &MCCtx = MF->getContext ();
29993015 MCSymbol *PostGetPCLabel =
30003016 MCCtx.createTempSymbol (" post_getpc" , /* AlwaysAddSuffix=*/ true );
30013017 GetPC->setPostInstrSymbol (*MF, PostGetPCLabel);
0 commit comments