summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-12-19 19:35:32 +0000
committerChris Lattner <sabre@nondot.org>2010-12-19 19:35:32 +0000
commit33dc3f0cfa89384f6b4e5684e1f17c8b8353949d (patch)
treebd5a67d51fd50eefc14d9331ee04556c41eb2335 /llvm/lib/Transforms/InstCombine
parent94f24db6f09f60948f162051adabeff2de39a166 (diff)
downloadbcm5719-llvm-33dc3f0cfa89384f6b4e5684e1f17c8b8353949d.tar.gz
bcm5719-llvm-33dc3f0cfa89384f6b4e5684e1f17c8b8353949d.zip
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. llvm-svn: 122181
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index d53f3291e71..f3a5e724c61 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -523,6 +523,21 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
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 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
return InsertValueInst::Create(Struct, II->getArgOperand(0), 0);
}
}
+
break;
case Intrinsic::usub_with_overflow:
case Intrinsic::ssub_with_overflow:
OpenPOWER on IntegriCloud