diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp index 786baa6820e86..06ed92e22e653 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -1415,23 +1415,8 @@ void GCNPassConfig::addFastRegAlloc() { } void GCNPassConfig::addOptimizedRegAlloc() { - // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation - // instructions that cause scheduling barriers. - insertPass(&MachineSchedulerID, &SIWholeQuadModeID); - - if (OptExecMaskPreRA) - insertPass(&MachineSchedulerID, &SIOptimizeExecMaskingPreRAID); - - if (EnableRewritePartialRegUses) - insertPass(&RenameIndependentSubregsID, &GCNRewritePartialRegUsesID); - - if (isPassEnabled(EnablePreRAOptimizations)) - insertPass(&RenameIndependentSubregsID, &GCNPreRAOptimizationsID); - - // This is not an essential optimization and it has a noticeable impact on - // compilation time, so we only enable it from O2. - if (TM->getOptLevel() > CodeGenOptLevel::Less) - insertPass(&MachineSchedulerID, &SIFormMemoryClausesID); + if (EnableDCEInRA) + insertPass(&DetectDeadLanesID, &DeadMachineInstructionElimID); // FIXME: when an instruction has a Killed operand, and the instruction is // inside a bundle, seems only the BUNDLE instruction appears as the Kills of @@ -1439,13 +1424,29 @@ void GCNPassConfig::addOptimizedRegAlloc() { // we should fix it and enable the verifier. if (OptVGPRLiveRange) insertPass(&LiveVariablesID, &SIOptimizeVGPRLiveRangeID); + // This must be run immediately after phi elimination and before // TwoAddressInstructions, otherwise the processing of the tied operand of // SI_ELSE will introduce a copy of the tied operand source after the else. insertPass(&PHIEliminationID, &SILowerControlFlowID); - if (EnableDCEInRA) - insertPass(&DetectDeadLanesID, &DeadMachineInstructionElimID); + if (EnableRewritePartialRegUses) + insertPass(&RenameIndependentSubregsID, &GCNRewritePartialRegUsesID); + + if (isPassEnabled(EnablePreRAOptimizations)) + insertPass(&RenameIndependentSubregsID, &GCNPreRAOptimizationsID); + + // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation + // instructions that cause scheduling barriers. + insertPass(&MachineSchedulerID, &SIWholeQuadModeID); + + if (OptExecMaskPreRA) + insertPass(&MachineSchedulerID, &SIOptimizeExecMaskingPreRAID); + + // This is not an essential optimization and it has a noticeable impact on + // compilation time, so we only enable it from O2. + if (TM->getOptLevel() > CodeGenOptLevel::Less) + insertPass(&MachineSchedulerID, &SIFormMemoryClausesID); TargetPassConfig::addOptimizedRegAlloc(); }