diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2015-04-13 19:17:37 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2015-04-13 19:17:37 +0000 |
| commit | abe2cc17dac0eacc47f2bbc4a41fa1ccc7ad8fe1 (patch) | |
| tree | fab87b3109ec0f1f662b1af604af96401e786902 /llvm/lib/Transforms/InstCombine | |
| parent | 2114275263405e842f34a313297889c5064535f5 (diff) | |
| download | bcm5719-llvm-abe2cc17dac0eacc47f2bbc4a41fa1ccc7ad8fe1.tar.gz bcm5719-llvm-abe2cc17dac0eacc47f2bbc4a41fa1ccc7ad8fe1.zip | |
Subtraction is not commutative. Fixes PR23212!
llvm-svn: 234780
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 13 | ||||
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 3 |
2 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 8c6dc099210..11094e99397 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/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<Constant>(II->getArgOperand(0)) && !isa<Constant>(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/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index e084d3d8b03..223bba03507 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/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<Constant>(LHS) && !isa<Constant>(RHS)) && + assert((!OrigI.isCommutative() || + !(isa<Constant>(LHS) && !isa<Constant>(RHS))) && "call with a constant RHS if possible!"); auto SetResult = [&](Value *OpResult, Constant *OverflowVal, bool ReuseName) { |

