Skip to content

Commit c49c220

Browse files
committed
[TSAR, Memory] Check step of locations with variable bounds.
1 parent 9c37a1e commit c49c220

File tree

4 files changed

+124
-106
lines changed

4 files changed

+124
-106
lines changed

include/tsar/Analysis/Memory/MemorySetInfo.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,14 @@ template<> struct MemorySetInfo<MemoryLocationRange> {
241241
!llvm::isa<llvm::SCEVConstant>(Left.End) ||
242242
!llvm::isa<llvm::SCEVConstant>(Right.Start) ||
243243
!llvm::isa<llvm::SCEVConstant>(Right.End)) {
244-
auto CmpLeftStartRightEnd = compareSCEVs(Left.Start, Right.End, SE);
245-
auto CmpRightStartLeftEnd = compareSCEVs(Right.Start, Left.End, SE);
246-
if (CmpLeftStartRightEnd &&
247-
(*CmpLeftStartRightEnd == 0 || *CmpLeftStartRightEnd == 1) ||
248-
CmpRightStartLeftEnd &&
249-
(*CmpRightStartLeftEnd == 0 || *CmpRightStartLeftEnd == 1)) {
244+
auto CmpLSRE = compareSCEVs(Left.Start, Right.End, SE);
245+
auto CmpRSLE = compareSCEVs(Right.Start, Left.End, SE);
246+
if (Left.Step == Right.Step &&
247+
llvm::isa<llvm::SCEVConstant>(Left.Step) &&
248+
llvm::cast<llvm::SCEVConstant>(Left.Step)->
249+
getAPInt().getSExtValue() == 1 &&
250+
CmpLSRE && (*CmpLSRE == 0 || *CmpLSRE == 1) ||
251+
CmpRSLE && (*CmpRSLE == 0 || *CmpRSLE == 1)) {
250252
++JoinableDimCount;
251253
continue;
252254
}
@@ -304,15 +306,13 @@ template<> struct MemorySetInfo<MemoryLocationRange> {
304306
!llvm::isa<llvm::SCEVConstant>(DimTo.End) ||
305307
!llvm::isa<llvm::SCEVConstant>(DimFrom.Start) ||
306308
!llvm::isa<llvm::SCEVConstant>(DimFrom.End)) {
307-
auto CmpFromEndToStart = compareSCEVs(DimTo.Start, DimFrom.End, SE);
308-
auto CmpToEndFromStart = compareSCEVs(DimFrom.Start, DimTo.End, SE);
309-
if (CmpFromEndToStart &&
310-
(*CmpFromEndToStart == 0 || *CmpFromEndToStart == 1)) {
309+
auto CmpTSFE = compareSCEVs(DimTo.Start, DimFrom.End, SE);
310+
auto CmpFSTE = compareSCEVs(DimFrom.Start, DimTo.End, SE);
311+
if (CmpTSFE && (*CmpTSFE == 0 || *CmpTSFE == 1)) {
311312
DimTo.Start = DimFrom.Start;
312313
IsChanged = true;
313314
}
314-
if (CmpToEndFromStart &&
315-
(*CmpToEndFromStart == 0 || *CmpToEndFromStart == 1)) {
315+
if (CmpFSTE && (*CmpFSTE == 0 || *CmpFSTE == 1)) {
316316
DimTo.End = DimFrom.End;
317317
IsChanged = true;
318318
}

lib/Analysis/Memory/DefinedMemory.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,15 @@ std::pair<MemoryLocationRange, bool> aggregate(
428428
if (Bounds->getDirection() == Loop::LoopBounds::Direction::Increasing) {
429429
if (Predicate == Predicate::ICMP_SLT ||
430430
Predicate == Predicate::ICMP_ULT) {
431-
FinalSCEV = SE->getMinusSCEV(FinalSCEV,
432-
SE->getOne(FinalSCEV->getType()));
431+
FinalSCEV = subtractSCEVAndCast(FinalSCEV,
432+
SE->getOne(FinalSCEV->getType()),
433+
SE);
433434
}
434435
} else {
435436
if (Predicate == Predicate::ICMP_SGT ||
436437
Predicate == Predicate::ICMP_UGT) {
437-
FinalSCEV = SE->getAddExpr(SE->getOne(FinalSCEV->getType()),
438-
FinalSCEV);
438+
FinalSCEV = addSCEVAndCast(SE->getOne(FinalSCEV->getType()),
439+
FinalSCEV, SE);
439440
}
440441
}
441442
LLVM_DEBUG(dbgs() << "[AGGREGATE] AddRecType: "; C->getType()->dump());
@@ -446,19 +447,19 @@ std::pair<MemoryLocationRange, bool> aggregate(
446447
if (LoopStep > 0 && IdxExprStep > 0) {
447448
DimInfo.Start = ZeroItr;
448449
DimInfo.End = C->evaluateAtIteration(
449-
SE->getMinusSCEV(FinalSCEV, InitSCEV), *SE);
450+
subtractSCEVAndCast(FinalSCEV, InitSCEV, SE), *SE);
450451
} else if (LoopStep > 0 && IdxExprStep < 0) {
451452
DimInfo.Start = C->evaluateAtIteration(
452-
SE->getMinusSCEV(FinalSCEV, InitSCEV), *SE);
453+
subtractSCEVAndCast(FinalSCEV, InitSCEV, SE), *SE);
453454
DimInfo.End = ZeroItr;
454455
} else if (LoopStep < 0 && IdxExprStep > 0) {
455456
DimInfo.Start = C->evaluateAtIteration(
456-
SE->getMinusSCEV(InitSCEV, FinalSCEV), *SE);
457+
subtractSCEVAndCast(InitSCEV, FinalSCEV, SE), *SE);
457458
DimInfo.End = ZeroItr;
458459
} else {
459460
DimInfo.Start = ZeroItr;
460461
DimInfo.End = C->evaluateAtIteration(
461-
SE->getMinusSCEV(InitSCEV, FinalSCEV), *SE);
462+
subtractSCEVAndCast(InitSCEV, FinalSCEV, SE), *SE);
462463
}
463464
auto CmpStartEnd = compareSCEVs(DimInfo.Start, DimInfo.End, SE);
464465
if (CmpStartEnd && *CmpStartEnd > 0) {

0 commit comments

Comments
 (0)