[llvm] r234780 - Subtraction is not commutative. Fixes PR23212!
Nick Lewycky
nicholas at mxc.ca
Mon Apr 13 12:17:38 PDT 2015
Author: nicholas
Date: Mon Apr 13 14:17:37 2015
New Revision: 234780
URL: http://llvm.org/viewvc/llvm-project?rev=234780&view=rev
Log:
Subtraction is not commutative. Fixes PR23212!
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/intrinsics.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=234780&r1=234779&r2=234780&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Mon Apr 13 14:17:37 2015
@@ -416,12 +416,10 @@ Instruction *InstCombiner::visitCallInst
}
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
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!");
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=234780&r1=234779&r2=234780&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Mon Apr 13 14:17:37 2015
@@ -2112,7 +2112,8 @@ static Instruction *ProcessUGT_ADDCST_AD
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) {
Modified: llvm/trunk/test/Transforms/InstCombine/intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intrinsics.ll?rev=234780&r1=234779&r2=234780&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intrinsics.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/intrinsics.ll Mon Apr 13 14:17:37 2015
@@ -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
+}
More information about the llvm-commits
mailing list