diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp --- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp +++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp @@ -1450,7 +1450,8 @@ // after one of the operands go to overdefined, e.g. due to one operand // being a special floating value. ValueLatticeElement NewV; - NewV.markConstant(C, /*MayIncludeUndef=*/true); + NewV.markConstant(C, V1State.isConstantRangeIncludingUndef() || + V2State.isConstantRangeIncludingUndef()); return (void)mergeInValue(&I, NewV); } } diff --git a/llvm/test/Transforms/SCCP/ip-ranges-phis.ll b/llvm/test/Transforms/SCCP/ip-ranges-phis.ll --- a/llvm/test/Transforms/SCCP/ip-ranges-phis.ll +++ b/llvm/test/Transforms/SCCP/ip-ranges-phis.ll @@ -56,11 +56,11 @@ ; CHECK-NEXT: [[V_2:%.*]] = select i1 [[C_2]], i32 20, i32 200 ; CHECK-NEXT: [[V_3:%.*]] = select i1 [[C_3]], i32 30, i32 300 ; CHECK-NEXT: [[R_1:%.*]] = add nuw nsw i32 [[V_1]], [[V_2]] -; CHECK-NEXT: [[R_2:%.*]] = add i32 [[R_1]], [[V_3]] -; CHECK-NEXT: [[R_3:%.*]] = add i32 [[R_2]], 400 -; CHECK-NEXT: [[R_4:%.*]] = add i32 [[R_3]], 50 -; CHECK-NEXT: [[R_5:%.*]] = add i32 [[R_4]], 60 -; CHECK-NEXT: [[R_6:%.*]] = add i32 [[R_4]], 700 +; CHECK-NEXT: [[R_2:%.*]] = add nuw nsw i32 [[R_1]], [[V_3]] +; CHECK-NEXT: [[R_3:%.*]] = add nuw nsw i32 [[R_2]], 400 +; CHECK-NEXT: [[R_4:%.*]] = add nuw nsw i32 [[R_3]], 50 +; CHECK-NEXT: [[R_5:%.*]] = add nuw nsw i32 [[R_4]], 60 +; CHECK-NEXT: [[R_6:%.*]] = add nuw nsw i32 [[R_4]], 700 ; CHECK-NEXT: ret i32 [[R_6]] ; @@ -111,7 +111,7 @@ ; CHECK-NEXT: [[P1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[IF_TRUE]] ] ; CHECK-NEXT: [[P2:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ -10, [[IF_TRUE]] ] ; CHECK-NEXT: [[P3:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ 10, [[IF_TRUE]] ] -; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f2(i32 [[P1]], i32 [[P2]], i32 [[P3]], i1 [[CMP_1]], i1 [[CMP_2]]) +; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f2(i32 [[P1]], i32 [[P2]], i32 [[P3]], i1 [[CMP_1]], i1 [[CMP_2]]), !range [[RNG0:![0-9]+]] ; CHECK-NEXT: ret i32 [[CALL1]] ; @@ -204,7 +204,7 @@ ; CHECK-NEXT: br label [[END]] ; CHECK: end: ; CHECK-NEXT: [[P1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 5, [[IF_TRUE]] ] -; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f3(i32 [[P1]], i32 [[Y]], i1 [[CMP_1]]), !range [[RNG0:![0-9]+]] +; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f3(i32 [[P1]], i32 [[Y]], i1 [[CMP_1]]), !range [[RNG1:![0-9]+]] ; CHECK-NEXT: ret i32 [[CALL1]] ;