@@ -921,14 +921,17 @@ void LowOverheadLoop::Validate(ARMBasicBlockUtils *BBUtils) {
921
921
if (Revert)
922
922
return ;
923
923
924
- auto ValidateRanges = [this , &BBUtils]() {
924
+ // Check branch target ranges: WLS[TP] can only branch forwards and LE[TP]
925
+ // can only jump back.
926
+ auto ValidateRanges = [](MachineInstr *Start, MachineInstr *End,
927
+ ARMBasicBlockUtils *BBUtils, MachineLoop &ML) {
925
928
if (!End->getOperand (1 ).isMBB ())
926
929
report_fatal_error (" Expected LoopEnd to target basic block" );
927
930
928
931
// TODO Maybe there's cases where the target doesn't have to be the header,
929
932
// but for now be safe and revert.
930
933
if (End->getOperand (1 ).getMBB () != ML.getHeader ()) {
931
- LLVM_DEBUG (dbgs () << " ARM Loops: LoopEnd is not targetting header.\n " );
934
+ LLVM_DEBUG (dbgs () << " ARM Loops: LoopEnd is not targeting header.\n " );
932
935
return false ;
933
936
}
934
937
@@ -950,7 +953,10 @@ void LowOverheadLoop::Validate(ARMBasicBlockUtils *BBUtils) {
950
953
return true ;
951
954
};
952
955
953
- auto FindStartInsertionPoint = [this ]() -> MachineInstr* {
956
+ // Find a suitable position to insert the loop start instruction. It needs to
957
+ // be able to safely define LR.
958
+ auto FindStartInsertionPoint = [](MachineInstr *Start,
959
+ ReachingDefAnalysis &RDA) -> MachineInstr* {
954
960
// We can define LR because LR already contains the same value.
955
961
if (Start->getOperand (0 ).getReg () == ARM::LR)
956
962
return Start;
@@ -983,8 +989,8 @@ void LowOverheadLoop::Validate(ARMBasicBlockUtils *BBUtils) {
983
989
return RDA.isSafeToDefRegAt (Start, ARM::LR) ? Start : nullptr ;
984
990
};
985
991
986
- InsertPt = FindStartInsertionPoint ();
987
- Revert = !ValidateRanges () || !InsertPt;
992
+ InsertPt = FindStartInsertionPoint (Start, RDA );
993
+ Revert = !ValidateRanges (Start, End, BBUtils, ML ) || !InsertPt;
988
994
CannotTailPredicate = !ValidateTailPredicate (InsertPt);
989
995
990
996
LLVM_DEBUG (if (!InsertPt)
0 commit comments