[llvm] r358052 - [InstCombine] Handle usubo always overflow
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 10 00:10:53 PDT 2019
Author: nikic
Date: Wed Apr 10 00:10:53 2019
New Revision: 358052
URL: http://llvm.org/viewvc/llvm-project?rev=358052&view=rev
Log:
[InstCombine] Handle usubo always overflow
Check AlwaysOverflow condition for usubo. The implementation is the
same as the existing handling for uaddo and umulo. Handling for saddo
and ssubo will follow (smulo doesn't have the necessary ValueTracking
support).
Differential Revision: https://reviews.llvm.org/D60483
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/with_overflow.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=358052&r1=358051&r2=358052&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Apr 10 00:10:53 2019
@@ -3997,6 +3997,9 @@ bool InstCombiner::OptimizeOverflowCheck
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)
Modified: llvm/trunk/test/Transforms/InstCombine/with_overflow.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/with_overflow.ll?rev=358052&r1=358051&r2=358052&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/with_overflow.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/with_overflow.ll Wed Apr 10 00:10:53 2019
@@ -544,8 +544,9 @@ define { i8, i1 } @uadd_always_overflow(
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)
More information about the llvm-commits
mailing list