From aba37b07e909b30636e06f33b456af3abaa8ed0e Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Sun, 29 Jul 2018 16:49:48 +0100 Subject: ShiftChecker: Avoid unneeded checks Do not instrument shift operations with constant shift operations that are smaller than the type size. --- lib/Module/Checks.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/Module') 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(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); -- cgit 1.4.1