about summary refs log tree commit diff homepage
path: root/lib/Module
diff options
context:
space:
mode:
authorMartin Nowack <m.nowack@imperial.ac.uk>2018-07-29 16:49:48 +0100
committerCristian Cadar <c.cadar@imperial.ac.uk>2018-10-24 14:15:25 +0300
commitaba37b07e909b30636e06f33b456af3abaa8ed0e (patch)
tree217e05c3d9fdbc845fbad8b58e3c6a965dbf35f6 /lib/Module
parentb90f6ad72e7991f3cebb892ff162645bb91168c8 (diff)
downloadklee-aba37b07e909b30636e06f33b456af3abaa8ed0e.tar.gz
ShiftChecker: Avoid unneeded checks
Do not instrument shift operations with constant shift operations that
are smaller than the type size.
Diffstat (limited to 'lib/Module')
-rw-r--r--lib/Module/Checks.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/Module/Checks.cpp b/lib/Module/Checks.cpp
index bd9a8bd3..53ba4266 100644
--- a/lib/Module/Checks.cpp
+++ b/lib/Module/Checks.cpp
@@ -104,6 +104,16 @@ bool OvershiftCheckPass::runOnModule(Module &M) {
         if (opcode != Instruction::Shl && opcode != Instruction::LShr &&
             opcode != Instruction::AShr)
           continue;
+
+        // Check if the operand is constant and not zero, skip in that case
+        auto operand = binOp->getOperand(1);
+        if (auto coOp = dyn_cast<llvm::ConstantInt>(operand)) {
+          auto typeWidth =
+              binOp->getOperand(0)->getType()->getScalarSizeInBits();
+          // If the constant shift is positive and smaller,equal the type width,
+          // we can ignore this instruction
+          if (!coOp->isNegative() && coOp->getZExtValue() < typeWidth)
+            continue;
         }
 
         shiftInstructions.push_back(binOp);