[llvm-commits] [llvm] r122181 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCalls.cpp test/Transforms/InstCombine/intrinsics.ll
Chris Lattner
sabre at nondot.org
Sun Dec 19 11:35:32 PST 2010
Author: lattner
Date: Sun Dec 19 13:35:32 2010
New Revision: 122181
URL: http://llvm.org/viewvc/llvm-project?rev=122181&view=rev
Log:
optimize uadd(x, cst) into a comparison when the normal
result is dead. This is required for my next patch to not
regress the testsuite.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.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=122181&r1=122180&r2=122181&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Sun Dec 19 13:35:32 2010
@@ -523,6 +523,21 @@
return InsertValueInst::Create(Struct, Add, 0);
}
}
+
+ // If the normal result of the add is dead, and the RHS is a constant, we
+ // can transform this into a range comparison.
+ // overflow = uadd a, -4 --> overflow = icmp ugt a, 3
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS))
+ if (ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(II->use_back()))
+ if (II->hasOneUse() && EVI->getNumIndices() == 1 && !EVI->use_empty() &&
+ *EVI->idx_begin() == 1) { // Extract of overflow result.
+ Builder->SetInsertPoint(EVI);
+ Value *R = Builder->CreateICmpUGT(LHS, ConstantExpr::getNot(CI));
+ R->takeName(EVI);
+ ReplaceInstUsesWith(*EVI, R);
+ return II;
+ }
+
}
// FALL THROUGH uadd into sadd
case Intrinsic::sadd_with_overflow:
@@ -550,6 +565,7 @@
return InsertValueInst::Create(Struct, II->getArgOperand(0), 0);
}
}
+
break;
case Intrinsic::usub_with_overflow:
case Intrinsic::ssub_with_overflow:
Modified: llvm/trunk/test/Transforms/InstCombine/intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intrinsics.ll?rev=122181&r1=122180&r2=122181&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intrinsics.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/intrinsics.ll Sun Dec 19 13:35:32 2010
@@ -71,6 +71,16 @@
; CHECK: ret i8 %A
}
+define i1 @uaddtest6(i8 %A, i8 %B) {
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %A, i8 -4)
+ %z = extractvalue %overflow.result %x, 1
+ ret i1 %z
+; CHECK: @uaddtest6
+; CHECK-NEXT: %z = icmp ugt i8 %A, 3
+; CHECK-NEXT: ret i1 %z
+}
+
+
define i8 @umultest1(i8 %A, i1* %overflowPtr) {
%x = call %overflow.result @llvm.umul.with.overflow.i8(i8 0, i8 %A)
%y = extractvalue %overflow.result %x, 0
More information about the llvm-commits
mailing list