assert(*EV.idx_begin() == 1 && "Unexpected extract index for overflow inst");
+ // (usub LHS, RHS) overflows when LHS is unsigned-less-than RHS.
+ if (OvID == Intrinsic::usub_with_overflow)
+ return new ICmpInst(ICmpInst::ICMP_ULT, WO->getLHS(), WO->getRHS());
+
// If only the overflow result is used, and the right hand side is a
// constant (or constant splat), we can remove the intrinsic by directly
// checking for overflow.
define i1 @test_generic(i64 %a, i64 %b) {
; CHECK-LABEL: @test_generic(
-; CHECK-NEXT: [[RES:%.*]] = tail call { i64, i1 } @llvm.usub.with.overflow.i64(i64 [[A:%.*]], i64 [[B:%.*]])
-; CHECK-NEXT: [[OVERFLOW:%.*]] = extractvalue { i64, i1 } [[RES]], 1
+; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ult i64 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i1 [[OVERFLOW]]
;
%res = tail call { i64, i1 } @llvm.usub.with.overflow.i64(i64 %a, i64 %b)