From: Nick Lewycky Date: Mon, 13 Apr 2015 19:17:37 +0000 (+0000) Subject: Subtraction is not commutative. Fixes PR23212! X-Git-Tag: android-x86-7.1-r4~49339 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=d4b4e3e20f1a212dbeb6f5b2876df4b550259e92;p=android-x86%2Fexternal-llvm.git Subtraction is not commutative. Fixes PR23212! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234780 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index 8c6dc099210..11094e99397 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -416,12 +416,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { } break; - case Intrinsic::uadd_with_overflow: // FALLTHROUGH - case Intrinsic::sadd_with_overflow: // FALLTHROUGH - case Intrinsic::usub_with_overflow: // FALLTHROUGH - case Intrinsic::ssub_with_overflow: // FALLTHROUGH - case Intrinsic::umul_with_overflow: // FALLTHROUGH - case Intrinsic::smul_with_overflow: { + case Intrinsic::uadd_with_overflow: + case Intrinsic::sadd_with_overflow: + case Intrinsic::umul_with_overflow: + case Intrinsic::smul_with_overflow: if (isa(II->getArgOperand(0)) && !isa(II->getArgOperand(1))) { // Canonicalize constants into the RHS. @@ -430,7 +428,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { II->setArgOperand(1, LHS); return II; } + [[clang::fallthrough]]; + case Intrinsic::usub_with_overflow: + case Intrinsic::ssub_with_overflow: { OverflowCheckFlavor OCF = IntrinsicIDToOverflowCheckFlavor(II->getIntrinsicID()); assert(OCF != OCF_INVALID && "unexpected!"); diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index e084d3d8b03..223bba03507 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2112,7 +2112,8 @@ static Instruction *ProcessUGT_ADDCST_ADD(ICmpInst &I, Value *A, Value *B, bool InstCombiner::OptimizeOverflowCheck(OverflowCheckFlavor OCF, Value *LHS, Value *RHS, Instruction &OrigI, Value *&Result, Constant *&Overflow) { - assert(!(isa(LHS) && !isa(RHS)) && + assert((!OrigI.isCommutative() || + !(isa(LHS) && !isa(RHS))) && "call with a constant RHS if possible!"); auto SetResult = [&](Value *OpResult, Constant *OverflowVal, bool ReuseName) { diff --git a/test/Transforms/InstCombine/intrinsics.ll b/test/Transforms/InstCombine/intrinsics.ll index 539628a31be..f9ccf51a621 100644 --- a/test/Transforms/InstCombine/intrinsics.ll +++ b/test/Transforms/InstCombine/intrinsics.ll @@ -407,3 +407,13 @@ entry: %obit = extractvalue %ov.result.32 %t, 1 ret i1 %obit } + +define %ov.result.32 @ssubtest_reorder(i8 %a) { + %A = sext i8 %a to i32 + %x = call %ov.result.32 @llvm.ssub.with.overflow.i32(i32 0, i32 %A) + ret %ov.result.32 %x +; CHECK-LABEL: @ssubtest_reorder +; CHECK: %x = sub nsw i32 0, %A +; CHECK-NEXT: %1 = insertvalue %ov.result.32 { i32 undef, i1 false }, i32 %x, 0 +; CHECK-NEXT: ret %ov.result.32 %1 +}