diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -824,6 +824,8 @@ switch (BinOp) { case Instruction::Add: return addWithNoWrap(Other, NoWrapKind); + case Instruction::Sub: + return subWithNoWrap(Other, NoWrapKind); default: // Don't know about this Overflowing Binary Operation. // Conservatively fallback to plain binop handling. diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll --- a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll +++ b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll @@ -490,11 +490,9 @@ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[A]], [[B]] ; CHECK-NEXT: br label [[CONT:%.*]] ; CHECK: cont: -; CHECK-NEXT: [[RES:%.*]] = icmp sge i32 [[SUB]], 0 ; CHECK-NEXT: br label [[EXIT]] ; CHECK: exit: -; CHECK-NEXT: [[IV:%.*]] = phi i1 [ true, [[BEGIN:%.*]] ], [ [[RES]], [[CONT]] ] -; CHECK-NEXT: ret i1 [[IV]] +; CHECK-NEXT: ret i1 true ; begin: %cmp0 = icmp sge i32 %a, 0 @@ -598,11 +596,9 @@ ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[A]], [[B]] ; CHECK-NEXT: br label [[CONT:%.*]] ; CHECK: cont: -; CHECK-NEXT: [[RES:%.*]] = icmp sle i32 [[SUB]], 0 ; CHECK-NEXT: br label [[EXIT]] ; CHECK: exit: -; CHECK-NEXT: [[IV:%.*]] = phi i1 [ true, [[BEGIN:%.*]] ], [ [[RES]], [[CONT]] ] -; CHECK-NEXT: ret i1 [[IV]] +; CHECK-NEXT: ret i1 true ; begin: %cmp0 = icmp sle i32 %a, 0