diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -2330,9 +2330,9 @@ buildPartialInvariantUnswitchConditionalBranch( *SplitBB, Invariants, Direction, *ClonedPH, *LoopPH, L, MSSAU); else { - buildPartialUnswitchConditionalBranch(*SplitBB, Invariants, Direction, - *ClonedPH, *LoopPH, InsertFreeze, - BI, &AC, DT); + buildPartialUnswitchConditionalBranch( + *SplitBB, Invariants, Direction, *ClonedPH, *LoopPH, + FreezeLoopUnswitchCond, BI, &AC, DT); } DTUpdates.push_back({DominatorTree::Insert, SplitBB, ClonedPH}); diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll --- a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll @@ -2717,7 +2717,8 @@ entry: br label %loop_begin ; CHECK-NEXT: entry: -; CHECK-NEXT: br i1 %cond, label %entry.split.us, label %entry.split +; CHECK-NEXT: [[FROZEN:%.+]] = freeze i1 %cond +; CHECK-NEXT: br i1 [[FROZEN]], label %entry.split.us, label %entry.split loop_begin: %v1 = load i1, i1* %ptr @@ -2790,7 +2791,9 @@ entry: br label %loop_begin ; CHECK-NEXT: entry: -; CHECK-NEXT: %[[INV_AND:.*]] = and i1 %cond3, %cond1 +; CHECK-NEXT: [[C3_FR:%.+]] = freeze i1 %cond3 +; CHECK-NEXT: [[C1_FR:%.+]] = freeze i1 %cond1 +; CHECK-NEXT: %[[INV_AND:.*]] = and i1 [[C3_FR]], [[C1_FR]] ; CHECK-NEXT: br i1 %[[INV_AND]], label %entry.split, label %entry.split.us loop_begin: @@ -2871,7 +2874,9 @@ entry: br label %loop_begin ; CHECK-NEXT: entry: -; CHECK-NEXT: %[[INV_OR:.*]] = or i1 %cond3, %cond1 +; CHECK-NEXT: [[C3_FR:%.+]] = freeze i1 %cond3 +; CHECK-NEXT: [[C1_FR:%.+]] = freeze i1 %cond1 +; CHECK-NEXT: %[[INV_OR:.*]] = or i1 [[C3_FR]], [[C1_FR]] ; CHECK-NEXT: br i1 %[[INV_OR]], label %entry.split.us, label %entry.split loop_begin: @@ -4231,7 +4236,9 @@ entry: br label %loop_begin ; CHECK-NEXT: entry: -; CHECK-NEXT: %[[INV_AND:.*]] = and i1 %cond2, %cond1 +; CHECK-NEXT: [[C2_FR:%.+]] = freeze i1 %cond2 +; CHECK-NEXT: [[C1_FR:%.+]] = freeze i1 %cond1 +; CHECK-NEXT: %[[INV_AND:.*]] = and i1 [[C2_FR]], [[C1_FR]] ; CHECK-NEXT: br i1 %[[INV_AND]], label %entry.split, label %entry.split.us loop_begin: @@ -4309,7 +4316,9 @@ entry: br label %loop_begin ; CHECK-NEXT: entry: -; CHECK-NEXT: %[[INV_OR:.*]] = or i1 %cond2, %cond1 +; CHECK-NEXT: [[C2_FR:%.+]] = freeze i1 %cond2 +; CHECK-NEXT: [[C1_FR:%.+]] = freeze i1 %cond1 +; CHECK-NEXT: %[[INV_OR:.*]] = or i1 [[C2_FR]], [[C1_FR]] ; CHECK-NEXT: br i1 %[[INV_OR]], label %entry.split.us, label %entry.split loop_begin: