aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorJohannes Doerfert <johannes@jdoerfert.de>2020-02-09 19:07:30 -0600
committerJohannes Doerfert <johannes@jdoerfert.de>2020-02-10 00:38:01 -0600
commitffdbd2a06ca2a2703647fb87140b8965b3b0218c (patch)
tree27b48178ff7b7914c897deb0f031a29527cc10e3 /llvm/lib
parent028db8c490bb29fb2fb7fab63771e72923d275fa (diff)
downloadllvm-ffdbd2a06ca2a2703647fb87140b8965b3b0218c.zip
llvm-ffdbd2a06ca2a2703647fb87140b8965b3b0218c.tar.gz
llvm-ffdbd2a06ca2a2703647fb87140b8965b3b0218c.tar.bz2
[Attributor] Look through (some) casts in AAValueConstantRangeFloating
Casts can be handled natively by the ConstantRange class. We do limit it to extends for now as we assume an integer type in different locations. A TODO and a test case with a FIXME was added to remove that restriction in the future.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/IPO/Attributor.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 8b97e3d..f16b9bc 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -6183,6 +6183,12 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
return;
}
+ // We handle casts in the updateImpl.
+ // TODO: Allow non integers as well.
+ if (CastInst *CI = dyn_cast<CastInst>(&V))
+ if (CI->getOperand(0)->getType()->isIntegerTy())
+ return;
+
// Otherwise we give up.
indicatePessimisticFixpoint();
@@ -6212,6 +6218,20 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
return T.isValidState();
}
+ bool calculateCastInst(Attributor &A, CastInst *CastI, IntegerRangeState &T,
+ Instruction *CtxI) {
+ assert(CastI->getNumOperands() == 1 && "Expected cast to be unary!");
+ // TODO: Allow non integers as well.
+ Value &OpV = *CastI->getOperand(0);
+ assert(OpV.getType()->isIntegerTy() && "Expected integer cast");
+
+ auto &OpAA =
+ A.getAAFor<AAValueConstantRange>(*this, IRPosition::value(OpV));
+ T.unionAssumed(
+ OpAA.getAssumed().castOp(CastI->getOpcode(), getState().getBitWidth()));
+ return T.isValidState();
+ }
+
bool calculateCmpInst(Attributor &A, CmpInst *CmpI, IntegerRangeState &T,
Instruction *CtxI) {
Value *LHS = CmpI->getOperand(0);
@@ -6282,6 +6302,8 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
return calculateBinaryOperator(A, BinOp, T, CtxI);
else if (auto *CmpI = dyn_cast<CmpInst>(I))
return calculateCmpInst(A, CmpI, T, CtxI);
+ else if (auto *CastI = dyn_cast<CastInst>(I))
+ return calculateCastInst(A, CastI, T, CtxI);
else {
// Give up with other instructions.
// TODO: Add other instructions