diff options
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/with_overflow.ll | 5 |
2 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index e274d7efddb..7ec75358f7b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3997,6 +3997,9 @@ bool InstCombiner::OptimizeOverflowCheck(OverflowCheckFlavor OCF, Value *LHS, if (OR == OverflowResult::NeverOverflows) return SetResult(Builder.CreateNUWSub(LHS, RHS), Builder.getFalse(), true); + + if (OR == OverflowResult::AlwaysOverflows) + return SetResult(Builder.CreateSub(LHS, RHS), Builder.getTrue(), true); } else { OR = computeOverflowForSignedSub(LHS, RHS, &OrigI); if (OR == OverflowResult::NeverOverflows) diff --git a/llvm/test/Transforms/InstCombine/with_overflow.ll b/llvm/test/Transforms/InstCombine/with_overflow.ll index d5854f4a2f1..d5a727ea194 100644 --- a/llvm/test/Transforms/InstCombine/with_overflow.ll +++ b/llvm/test/Transforms/InstCombine/with_overflow.ll @@ -544,8 +544,9 @@ define { i8, i1 } @uadd_always_overflow(i8 %x) nounwind { define { i8, i1 } @usub_always_overflow(i8 %x) nounwind { ; CHECK-LABEL: @usub_always_overflow( ; CHECK-NEXT: [[Y:%.*]] = or i8 [[X:%.*]], 64 -; CHECK-NEXT: [[A:%.*]] = call { i8, i1 } @llvm.usub.with.overflow.i8(i8 63, i8 [[Y]]) -; CHECK-NEXT: ret { i8, i1 } [[A]] +; CHECK-NEXT: [[A:%.*]] = sub nsw i8 63, [[Y]] +; CHECK-NEXT: [[TMP1:%.*]] = insertvalue { i8, i1 } { i8 undef, i1 true }, i8 [[A]], 0 +; CHECK-NEXT: ret { i8, i1 } [[TMP1]] ; %y = or i8 %x, 64 %a = call { i8, i1 } @llvm.usub.with.overflow.i8(i8 63, i8 %y) |