about summary refs log tree commit diff homepage
path: root/lib
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2012-04-10 01:05:46 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2012-04-10 01:05:46 +0000
commit461594277fe53d64ab89b02856232276916379d6 (patch)
treee9c65659a692cb1db9baa1f7ab72cb36b831a048 /lib
parent7ee405c0c792aef83435a2a6fc0a10734f47ba97 (diff)
downloadklee-461594277fe53d64ab89b02856232276916379d6.tar.gz
Lowering support for the llvm.uadd.with.overflow intrinsic.
git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@154367 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Module/IntrinsicCleaner.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp
index 8e326af9..8b0be35a 100644
--- a/lib/Module/IntrinsicCleaner.cpp
+++ b/lib/Module/IntrinsicCleaner.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/Type.h"
+#include "llvm/Support/IRBuilder.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Target/TargetData.h"
@@ -94,6 +95,31 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b) {
         break;
       }
 
+      case Intrinsic::uadd_with_overflow: {
+        IRBuilder<> builder(ii->getParent(), ii);
+
+#if LLVM_VERSION_CODE < LLVM_VERSION(2, 8)
+        Value *op1 = ii->getOperand(1);
+        Value *op2 = ii->getOperand(2);
+#else
+        Value *op1 = ii->getArgOperand(0);
+        Value *op2 = ii->getArgOperand(1);
+#endif
+        
+        Value *result = builder.CreateAdd(op1, op2);
+        Value *overflow = builder.CreateICmpULT(result, op1);
+        
+        Value *resultStruct =
+          builder.CreateInsertValue(UndefValue::get(ii->getType()), result, 0);
+        resultStruct = builder.CreateInsertValue(resultStruct, overflow, 1);
+        
+        ii->replaceAllUsesWith(resultStruct);
+        ii->removeFromParent();
+        delete ii;
+        dirty = true;
+        break;
+      }
+
 #if LLVM_VERSION_CODE < LLVM_VERSION(2, 7)
       case Intrinsic::dbg_stoppoint: {
         // We can remove this stoppoint if the next instruction is