aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis
diff options
context:
space:
mode:
authorEvan Phoenix <evan@fallingsnow.net>2009-10-05 22:53:52 +0000
committerEvan Phoenix <evan@fallingsnow.net>2009-10-05 22:53:52 +0000
commit1614e50d9f6d48a38e4dafb4b1a51fd4b37614f3 (patch)
treeef6179ab52f9523c7bc8760e4091a54ae11fb07d /lib/Analysis
parent540b05d227a79443b2a7b07d5152a35cb6392abf (diff)
downloadexternal_llvm-1614e50d9f6d48a38e4dafb4b1a51fd4b37614f3.zip
external_llvm-1614e50d9f6d48a38e4dafb4b1a51fd4b37614f3.tar.gz
external_llvm-1614e50d9f6d48a38e4dafb4b1a51fd4b37614f3.tar.bz2
Extend ConstantFolding to understand signed overflow variants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83338 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ConstantFolding.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 1ca7cb0..0ce1c24 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -678,6 +678,8 @@ llvm::canConstantFoldCallTo(const Function *F) {
case Intrinsic::cttz:
case Intrinsic::uadd_with_overflow:
case Intrinsic::usub_with_overflow:
+ case Intrinsic::sadd_with_overflow:
+ case Intrinsic::ssub_with_overflow:
return true;
default:
return false;
@@ -902,6 +904,28 @@ llvm::ConstantFoldCall(Function *F,
};
return ConstantStruct::get(F->getContext(), Ops, 2, false);
}
+ case Intrinsic::sadd_with_overflow: {
+ Constant *Res = ConstantExpr::getAdd(Op1, Op2); // result.
+ Constant *Overflow = ConstantExpr::getSelect(
+ ConstantExpr::getICmp(CmpInst::ICMP_SGT,
+ ConstantInt::get(Op1->getType(), 0), Op1),
+ ConstantExpr::getICmp(CmpInst::ICMP_SGT, Res, Op2),
+ ConstantExpr::getICmp(CmpInst::ICMP_SLT, Res, Op2)); // overflow.
+
+ Constant *Ops[] = { Res, Overflow };
+ return ConstantStruct::get(F->getContext(), Ops, 2, false);
+ }
+ case Intrinsic::ssub_with_overflow: {
+ Constant *Res = ConstantExpr::getSub(Op1, Op2); // result.
+ Constant *Overflow = ConstantExpr::getSelect(
+ ConstantExpr::getICmp(CmpInst::ICMP_SGT,
+ ConstantInt::get(Op2->getType(), 0), Op2),
+ ConstantExpr::getICmp(CmpInst::ICMP_SLT, Res, Op1),
+ ConstantExpr::getICmp(CmpInst::ICMP_SGT, Res, Op1)); // overflow.
+
+ Constant *Ops[] = { Res, Overflow };
+ return ConstantStruct::get(F->getContext(), Ops, 2, false);
+ }
}
}