mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-04 07:32:13 +00:00
Add the ability to track HasNSW and HasNUW on more kinds of SCEV expressions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83601 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5631139a69
commit
3645b01002
@ -402,37 +402,45 @@ namespace llvm {
|
||||
const SCEV *getZeroExtendExpr(const SCEV *Op, const Type *Ty);
|
||||
const SCEV *getSignExtendExpr(const SCEV *Op, const Type *Ty);
|
||||
const SCEV *getAnyExtendExpr(const SCEV *Op, const Type *Ty);
|
||||
const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops);
|
||||
const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS) {
|
||||
const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
|
||||
bool HasNUW = false, bool HasNSW = false);
|
||||
const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS,
|
||||
bool HasNUW = false, bool HasNSW = false) {
|
||||
SmallVector<const SCEV *, 2> Ops;
|
||||
Ops.push_back(LHS);
|
||||
Ops.push_back(RHS);
|
||||
return getAddExpr(Ops);
|
||||
return getAddExpr(Ops, HasNUW, HasNSW);
|
||||
}
|
||||
const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1,
|
||||
const SCEV *Op2) {
|
||||
const SCEV *Op2,
|
||||
bool HasNUW = false, bool HasNSW = false) {
|
||||
SmallVector<const SCEV *, 3> Ops;
|
||||
Ops.push_back(Op0);
|
||||
Ops.push_back(Op1);
|
||||
Ops.push_back(Op2);
|
||||
return getAddExpr(Ops);
|
||||
return getAddExpr(Ops, HasNUW, HasNSW);
|
||||
}
|
||||
const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops);
|
||||
const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS) {
|
||||
const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
|
||||
bool HasNUW = false, bool HasNSW = false);
|
||||
const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS,
|
||||
bool HasNUW = false, bool HasNSW = false) {
|
||||
SmallVector<const SCEV *, 2> Ops;
|
||||
Ops.push_back(LHS);
|
||||
Ops.push_back(RHS);
|
||||
return getMulExpr(Ops);
|
||||
return getMulExpr(Ops, HasNUW, HasNSW);
|
||||
}
|
||||
const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS);
|
||||
const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step,
|
||||
const Loop *L);
|
||||
const Loop *L,
|
||||
bool HasNUW = false, bool HasNSW = false);
|
||||
const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
|
||||
const Loop *L);
|
||||
const Loop *L,
|
||||
bool HasNUW = false, bool HasNSW = false);
|
||||
const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
|
||||
const Loop *L) {
|
||||
const Loop *L,
|
||||
bool HasNUW = false, bool HasNSW = false) {
|
||||
SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end());
|
||||
return getAddRecExpr(NewOp, L);
|
||||
return getAddRecExpr(NewOp, L, HasNUW, HasNSW);
|
||||
}
|
||||
const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
|
||||
const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
|
||||
|
@ -234,6 +234,15 @@ namespace llvm {
|
||||
|
||||
virtual const Type *getType() const { return getOperand(0)->getType(); }
|
||||
|
||||
bool hasNoUnsignedWrap() const { return SubclassData & (1 << 0); }
|
||||
void setHasNoUnsignedWrap(bool B) {
|
||||
SubclassData = (SubclassData & ~(1 << 0)) | (B << 0);
|
||||
}
|
||||
bool hasNoSignedWrap() const { return SubclassData & (1 << 1); }
|
||||
void setHasNoSignedWrap(bool B) {
|
||||
SubclassData = (SubclassData & ~(1 << 1)) | (B << 1);
|
||||
}
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
static inline bool classof(const SCEVNAryExpr *S) { return true; }
|
||||
static inline bool classof(const SCEV *S) {
|
||||
@ -436,15 +445,6 @@ namespace llvm {
|
||||
return cast<SCEVAddRecExpr>(SE.getAddExpr(this, getStepRecurrence(SE)));
|
||||
}
|
||||
|
||||
bool hasNoUnsignedWrap() const { return SubclassData & (1 << 0); }
|
||||
void setHasNoUnsignedWrap(bool B) {
|
||||
SubclassData = (SubclassData & ~(1 << 0)) | (B << 0);
|
||||
}
|
||||
bool hasNoSignedWrap() const { return SubclassData & (1 << 1); }
|
||||
void setHasNoSignedWrap(bool B) {
|
||||
SubclassData = (SubclassData & ~(1 << 1)) | (B << 1);
|
||||
}
|
||||
|
||||
virtual void print(raw_ostream &OS) const;
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
@ -464,6 +464,9 @@ namespace llvm {
|
||||
SCEVSMaxExpr(const FoldingSetNodeID &ID,
|
||||
const SmallVectorImpl<const SCEV *> &ops)
|
||||
: SCEVCommutativeExpr(ID, scSMaxExpr, ops) {
|
||||
// Max never overflows.
|
||||
setHasNoUnsignedWrap(true);
|
||||
setHasNoSignedWrap(true);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -486,6 +489,9 @@ namespace llvm {
|
||||
SCEVUMaxExpr(const FoldingSetNodeID &ID,
|
||||
const SmallVectorImpl<const SCEV *> &ops)
|
||||
: SCEVCommutativeExpr(ID, scUMaxExpr, ops) {
|
||||
// Max never overflows.
|
||||
setHasNoUnsignedWrap(true);
|
||||
setHasNoSignedWrap(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -1191,7 +1191,8 @@ namespace {
|
||||
|
||||
/// getAddExpr - Get a canonical add expression, or something simpler if
|
||||
/// possible.
|
||||
const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops) {
|
||||
const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
|
||||
bool HasNUW, bool HasNSW) {
|
||||
assert(!Ops.empty() && "Cannot get empty add!");
|
||||
if (Ops.size() == 1) return Ops[0];
|
||||
#ifndef NDEBUG
|
||||
@ -1241,7 +1242,7 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops) {
|
||||
return Mul;
|
||||
Ops.erase(Ops.begin()+i, Ops.begin()+i+2);
|
||||
Ops.push_back(Mul);
|
||||
return getAddExpr(Ops);
|
||||
return getAddExpr(Ops, HasNUW, HasNSW);
|
||||
}
|
||||
|
||||
// Check for truncates. If all the operands are truncated from the same
|
||||
@ -1296,7 +1297,7 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops) {
|
||||
}
|
||||
if (Ok) {
|
||||
// Evaluate the expression in the larger type.
|
||||
const SCEV *Fold = getAddExpr(LargeOps);
|
||||
const SCEV *Fold = getAddExpr(LargeOps, HasNUW, HasNSW);
|
||||
// If it folds to something simple, use it. Otherwise, don't.
|
||||
if (isa<SCEVConstant>(Fold) || isa<SCEVUnknown>(Fold))
|
||||
return getTruncateExpr(Fold, DstType);
|
||||
@ -1516,16 +1517,19 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops) {
|
||||
ID.AddPointer(Ops[i]);
|
||||
void *IP = 0;
|
||||
if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) return S;
|
||||
SCEV *S = SCEVAllocator.Allocate<SCEVAddExpr>();
|
||||
SCEVAddExpr *S = SCEVAllocator.Allocate<SCEVAddExpr>();
|
||||
new (S) SCEVAddExpr(ID, Ops);
|
||||
UniqueSCEVs.InsertNode(S, IP);
|
||||
if (HasNUW) S->setHasNoUnsignedWrap(true);
|
||||
if (HasNSW) S->setHasNoSignedWrap(true);
|
||||
return S;
|
||||
}
|
||||
|
||||
|
||||
/// getMulExpr - Get a canonical multiply expression, or something simpler if
|
||||
/// possible.
|
||||
const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops) {
|
||||
const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
|
||||
bool HasNUW, bool HasNSW) {
|
||||
assert(!Ops.empty() && "Cannot get empty mul!");
|
||||
#ifndef NDEBUG
|
||||
for (unsigned i = 1, e = Ops.size(); i != e; ++i)
|
||||
@ -1688,9 +1692,11 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops) {
|
||||
ID.AddPointer(Ops[i]);
|
||||
void *IP = 0;
|
||||
if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) return S;
|
||||
SCEV *S = SCEVAllocator.Allocate<SCEVMulExpr>();
|
||||
SCEVMulExpr *S = SCEVAllocator.Allocate<SCEVMulExpr>();
|
||||
new (S) SCEVMulExpr(ID, Ops);
|
||||
UniqueSCEVs.InsertNode(S, IP);
|
||||
if (HasNUW) S->setHasNoUnsignedWrap(true);
|
||||
if (HasNSW) S->setHasNoSignedWrap(true);
|
||||
return S;
|
||||
}
|
||||
|
||||
@ -1797,7 +1803,8 @@ const SCEV *ScalarEvolution::getUDivExpr(const SCEV *LHS,
|
||||
/// getAddRecExpr - Get an add recurrence expression for the specified loop.
|
||||
/// Simplify the expression as much as possible.
|
||||
const SCEV *ScalarEvolution::getAddRecExpr(const SCEV *Start,
|
||||
const SCEV *Step, const Loop *L) {
|
||||
const SCEV *Step, const Loop *L,
|
||||
bool HasNUW, bool HasNSW) {
|
||||
SmallVector<const SCEV *, 4> Operands;
|
||||
Operands.push_back(Start);
|
||||
if (const SCEVAddRecExpr *StepChrec = dyn_cast<SCEVAddRecExpr>(Step))
|
||||
@ -1808,14 +1815,15 @@ const SCEV *ScalarEvolution::getAddRecExpr(const SCEV *Start,
|
||||
}
|
||||
|
||||
Operands.push_back(Step);
|
||||
return getAddRecExpr(Operands, L);
|
||||
return getAddRecExpr(Operands, L, HasNUW, HasNSW);
|
||||
}
|
||||
|
||||
/// getAddRecExpr - Get an add recurrence expression for the specified loop.
|
||||
/// Simplify the expression as much as possible.
|
||||
const SCEV *
|
||||
ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
|
||||
const Loop *L) {
|
||||
const Loop *L,
|
||||
bool HasNUW, bool HasNSW) {
|
||||
if (Operands.size() == 1) return Operands[0];
|
||||
#ifndef NDEBUG
|
||||
for (unsigned i = 1, e = Operands.size(); i != e; ++i)
|
||||
@ -1826,7 +1834,7 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
|
||||
|
||||
if (Operands.back()->isZero()) {
|
||||
Operands.pop_back();
|
||||
return getAddRecExpr(Operands, L); // {X,+,0} --> X
|
||||
return getAddRecExpr(Operands, L, HasNUW, HasNSW); // {X,+,0} --> X
|
||||
}
|
||||
|
||||
// Canonicalize nested AddRecs in by nesting them in order of loop depth.
|
||||
@ -1855,7 +1863,7 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
|
||||
}
|
||||
if (AllInvariant)
|
||||
// Ok, both add recurrences are valid after the transformation.
|
||||
return getAddRecExpr(NestedOperands, NestedLoop);
|
||||
return getAddRecExpr(NestedOperands, NestedLoop, HasNUW, HasNSW);
|
||||
}
|
||||
// Reset Operands to its original state.
|
||||
Operands[0] = NestedAR;
|
||||
@ -1870,9 +1878,11 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
|
||||
ID.AddPointer(L);
|
||||
void *IP = 0;
|
||||
if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) return S;
|
||||
SCEV *S = SCEVAllocator.Allocate<SCEVAddRecExpr>();
|
||||
SCEVAddRecExpr *S = SCEVAllocator.Allocate<SCEVAddRecExpr>();
|
||||
new (S) SCEVAddRecExpr(ID, Operands, L);
|
||||
UniqueSCEVs.InsertNode(S, IP);
|
||||
if (HasNUW) S->setHasNoUnsignedWrap(true);
|
||||
if (HasNSW) S->setHasNoSignedWrap(true);
|
||||
return S;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user