aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/Module
diff options
context:
space:
mode:
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);