Skip to content

Commit 65a89cd

Browse files
committed
[TSAR, Memory] Check step of locations with variable bounds.
1 parent 03b1ee2 commit 65a89cd

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
@@ -246,12 +246,14 @@ template<> struct MemorySetInfo<MemoryLocationRange> {
246246
!llvm::isa<llvm::SCEVConstant>(Left.End) ||
247247
!llvm::isa<llvm::SCEVConstant>(Right.Start) ||
248248
!llvm::isa<llvm::SCEVConstant>(Right.End)) {
249-
auto CmpLeftStartRightEnd = compareSCEVs(Left.Start, Right.End, SE);
250-
auto CmpRightStartLeftEnd = compareSCEVs(Right.Start, Left.End, SE);
251-
if (CmpLeftStartRightEnd &&
252-
(*CmpLeftStartRightEnd == 0 || *CmpLeftStartRightEnd == 1) ||
253-
CmpRightStartLeftEnd &&
254-
(*CmpRightStartLeftEnd == 0 || *CmpRightStartLeftEnd == 1)) {
249+
auto CmpLSRE = compareSCEVs(Left.Start, Right.End, SE);
250+
auto CmpRSLE = compareSCEVs(Right.Start, Left.End, SE);
251+
if (Left.Step == Right.Step &&
252+
llvm::isa<llvm::SCEVConstant>(Left.Step) &&
253+
llvm::cast<llvm::SCEVConstant>(Left.Step)->
254+
getAPInt().getSExtValue() == 1 &&
255+
CmpLSRE && (*CmpLSRE == 0 || *CmpLSRE == 1) ||
256+
CmpRSLE && (*CmpRSLE == 0 || *CmpRSLE == 1)) {
255257
++JoinableDimCount;
256258
continue;
257259
}
@@ -309,15 +311,13 @@ template<> struct MemorySetInfo<MemoryLocationRange> {
309311
!llvm::isa<llvm::SCEVConstant>(DimTo.End) ||
310312
!llvm::isa<llvm::SCEVConstant>(DimFrom.Start) ||
311313
!llvm::isa<llvm::SCEVConstant>(DimFrom.End)) {
312-
auto CmpFromEndToStart = compareSCEVs(DimTo.Start, DimFrom.End, SE);
313-
auto CmpToEndFromStart = compareSCEVs(DimFrom.Start, DimTo.End, SE);
314-
if (CmpFromEndToStart &&
315-
(*CmpFromEndToStart == 0 || *CmpFromEndToStart == 1)) {
314+
auto CmpTSFE = compareSCEVs(DimTo.Start, DimFrom.End, SE);
315+
auto CmpFSTE = compareSCEVs(DimFrom.Start, DimTo.End, SE);
316+
if (CmpTSFE && (*CmpTSFE == 0 || *CmpTSFE == 1)) {
316317
DimTo.Start = DimFrom.Start;
317318
IsChanged = true;
318319
}
319-
if (CmpToEndFromStart &&
320-
(*CmpToEndFromStart == 0 || *CmpToEndFromStart == 1)) {
320+
if (CmpFSTE && (*CmpFSTE == 0 || *CmpFSTE == 1)) {
321321
DimTo.End = DimFrom.End;
322322
IsChanged = true;
323323
}

lib/Analysis/Memory/DefinedMemory.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,15 @@ std::pair<MemoryLocationRange, bool> aggregate(
427427
if (Bounds->getDirection() == Loop::LoopBounds::Direction::Increasing) {
428428
if (Predicate == Predicate::ICMP_SLT ||
429429
Predicate == Predicate::ICMP_ULT) {
430-
FinalSCEV = SE->getMinusSCEV(FinalSCEV,
431-
SE->getOne(FinalSCEV->getType()));
430+
FinalSCEV = subtractSCEVAndCast(FinalSCEV,
431+
SE->getOne(FinalSCEV->getType()),
432+
SE);
432433
}
433434
} else {
434435
if (Predicate == Predicate::ICMP_SGT ||
435436
Predicate == Predicate::ICMP_UGT) {
436-
FinalSCEV = SE->getAddExpr(SE->getOne(FinalSCEV->getType()),
437-
FinalSCEV);
437+
FinalSCEV = addSCEVAndCast(SE->getOne(FinalSCEV->getType()),
438+
FinalSCEV, SE);
438439
}
439440
}
440441
LLVM_DEBUG(dbgs() << "[AGGREGATE] AddRecType: "; C->getType()->dump());
@@ -445,19 +446,19 @@ std::pair<MemoryLocationRange, bool> aggregate(
445446
if (LoopStep > 0 && IdxExprStep > 0) {
446447
DimInfo.Start = ZeroItr;
447448
DimInfo.End = C->evaluateAtIteration(
448-
SE->getMinusSCEV(FinalSCEV, InitSCEV), *SE);
449+
subtractSCEVAndCast(FinalSCEV, InitSCEV, SE), *SE);
449450
} else if (LoopStep > 0 && IdxExprStep < 0) {
450451
DimInfo.Start = C->evaluateAtIteration(
451-
SE->getMinusSCEV(FinalSCEV, InitSCEV), *SE);
452+
subtractSCEVAndCast(FinalSCEV, InitSCEV, SE), *SE);
452453
DimInfo.End = ZeroItr;
453454
} else if (LoopStep < 0 && IdxExprStep > 0) {
454455
DimInfo.Start = C->evaluateAtIteration(
455-
SE->getMinusSCEV(InitSCEV, FinalSCEV), *SE);
456+
subtractSCEVAndCast(InitSCEV, FinalSCEV, SE), *SE);
456457
DimInfo.End = ZeroItr;
457458
} else {
458459
DimInfo.Start = ZeroItr;
459460
DimInfo.End = C->evaluateAtIteration(
460-
SE->getMinusSCEV(InitSCEV, FinalSCEV), *SE);
461+
subtractSCEVAndCast(InitSCEV, FinalSCEV, SE), *SE);
461462
}
462463
auto CmpStartEnd = compareSCEVs(DimInfo.Start, DimInfo.End, SE);
463464
if (CmpStartEnd && *CmpStartEnd > 0) {

0 commit comments

Comments
 (0)