summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2019-07-09 19:26:12 +0000
committerPhilip Reames <listmail@philipreames.com>2019-07-09 19:26:12 +0000
commit3dbd7e98d86a306f7ba125d042846099a56b6ee9 (patch)
tree26f741b4f2bb11403ca61c8fa9edfa88fd2102ac /llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp
parentf09d54ed2a75b62960b35258136435d7c8d418e1 (diff)
downloadbcm5719-llvm-3dbd7e98d86a306f7ba125d042846099a56b6ee9.tar.gz
bcm5719-llvm-3dbd7e98d86a306f7ba125d042846099a56b6ee9.zip
[PoisonCheker] Support for out of bounds operands on shifts + insert/extractelement
These are sources of poison which don't come from flags, but are clearly documented in the LangRef. Left off support for scalable vectors for the moment, but should be easy to add if anyone is interested. llvm-svn: 365543
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp')
-rw-r--r--llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp b/llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp
index 8e4c046c9f8..0c4e64bbc54 100644
--- a/llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp
@@ -169,14 +169,54 @@ static void generatePoisonChecksForBinOp(Instruction &I,
}
break;
}
+ case Instruction::AShr:
+ case Instruction::LShr:
+ case Instruction::Shl: {
+ Value *ShiftCheck =
+ B.CreateICmp(ICmpInst::ICMP_UGE, RHS,
+ ConstantInt::get(RHS->getType(),
+ LHS->getType()->getScalarSizeInBits()));
+ Checks.push_back(ShiftCheck);
+ break;
+ }
};
}
static Value* generatePoisonChecks(Instruction &I) {
IRBuilder<> B(&I);
SmallVector<Value*, 2> Checks;
- if (isa<BinaryOperator>(I))
+ if (isa<BinaryOperator>(I) && !I.getType()->isVectorTy())
generatePoisonChecksForBinOp(I, Checks);
+
+ // Handle non-binops seperately
+ switch (I.getOpcode()) {
+ default:
+ break;
+ case Instruction::ExtractElement: {
+ Value *Vec = I.getOperand(0);
+ if (Vec->getType()->getVectorIsScalable())
+ break;
+ Value *Idx = I.getOperand(1);
+ unsigned NumElts = Vec->getType()->getVectorNumElements();
+ Value *Check =
+ B.CreateICmp(ICmpInst::ICMP_UGE, Idx,
+ ConstantInt::get(Idx->getType(), NumElts));
+ Checks.push_back(Check);
+ break;
+ }
+ case Instruction::InsertElement: {
+ Value *Vec = I.getOperand(0);
+ if (Vec->getType()->getVectorIsScalable())
+ break;
+ Value *Idx = I.getOperand(2);
+ unsigned NumElts = Vec->getType()->getVectorNumElements();
+ Value *Check =
+ B.CreateICmp(ICmpInst::ICMP_UGE, Idx,
+ ConstantInt::get(Idx->getType(), NumElts));
+ Checks.push_back(Check);
+ break;
+ }
+ };
return buildOrChain(B, Checks);
}
OpenPOWER on IntegriCloud