From bea42108cfaa1623d7bc4b3435ac3c3f75d6906e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 10 Apr 2019 16:32:15 +0000 Subject: [PATCH] [InstCombine] Handle ssubo always overflow Following D60483 and D60497, this adds support for AlwaysOverflows handling for ssubo. This is the last case we can handle right now. Differential Revision: https://reviews.llvm.org/D60518 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358100 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCompares.cpp | 6 +++--- test/Transforms/InstCombine/with_overflow.ll | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index bc99b177a7e..2c7d70e4db4 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3997,15 +3997,15 @@ 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) return SetResult(Builder.CreateNSWSub(LHS, RHS), Builder.getFalse(), true); } + + if (OR == OverflowResult::AlwaysOverflows) + return SetResult(Builder.CreateSub(LHS, RHS), Builder.getTrue(), true); break; } diff --git a/test/Transforms/InstCombine/with_overflow.ll b/test/Transforms/InstCombine/with_overflow.ll index af9b1333497..e80da2afe2f 100644 --- a/test/Transforms/InstCombine/with_overflow.ll +++ b/test/Transforms/InstCombine/with_overflow.ll @@ -582,8 +582,9 @@ define { i8, i1 } @ssub_always_overflow(i8 %x) nounwind { ; CHECK-LABEL: @ssub_always_overflow( ; CHECK-NEXT: [[C:%.*]] = icmp sgt i8 [[X:%.*]], 29 ; CHECK-NEXT: [[Y:%.*]] = select i1 [[C]], i8 [[X]], i8 29 -; CHECK-NEXT: [[A:%.*]] = call { i8, i1 } @llvm.ssub.with.overflow.i8(i8 -100, i8 [[Y]]) -; CHECK-NEXT: ret { i8, i1 } [[A]] +; CHECK-NEXT: [[A:%.*]] = sub nuw i8 -100, [[Y]] +; CHECK-NEXT: [[TMP1:%.*]] = insertvalue { i8, i1 } { i8 undef, i1 true }, i8 [[A]], 0 +; CHECK-NEXT: ret { i8, i1 } [[TMP1]] ; %c = icmp sgt i8 %x, 29 %y = select i1 %c, i8 %x, i8 29 -- 2.50.1