@@ -1071,8 +1071,8 @@ static bool handleEndBlock(BasicBlock &BB, AliasAnalysis *AA,
1071
1071
}
1072
1072
1073
1073
static bool tryToShorten (Instruction *EarlierWrite, int64_t &EarlierOffset,
1074
- int64_t &EarlierSize, int64_t LaterOffset,
1075
- int64_t LaterSize, bool IsOverwriteEnd) {
1074
+ uint64_t &EarlierSize, int64_t LaterOffset,
1075
+ uint64_t LaterSize, bool IsOverwriteEnd) {
1076
1076
// TODO: base this on the target vector size so that if the earlier
1077
1077
// store was too small to get vector writes anyway then its likely
1078
1078
// a good idea to shorten it
@@ -1127,16 +1127,23 @@ static bool tryToShorten(Instruction *EarlierWrite, int64_t &EarlierOffset,
1127
1127
1128
1128
static bool tryToShortenEnd (Instruction *EarlierWrite,
1129
1129
OverlapIntervalsTy &IntervalMap,
1130
- int64_t &EarlierStart, int64_t &EarlierSize) {
1130
+ int64_t &EarlierStart, uint64_t &EarlierSize) {
1131
1131
if (IntervalMap.empty () || !isShortenableAtTheEnd (EarlierWrite))
1132
1132
return false ;
1133
1133
1134
1134
OverlapIntervalsTy::iterator OII = --IntervalMap.end ();
1135
1135
int64_t LaterStart = OII->second ;
1136
- int64_t LaterSize = OII->first - LaterStart;
1136
+ uint64_t LaterSize = OII->first - LaterStart;
1137
1137
1138
- if (LaterStart > EarlierStart && LaterStart < EarlierStart + EarlierSize &&
1139
- LaterStart + LaterSize >= EarlierStart + EarlierSize) {
1138
+ assert (OII->first - LaterStart >= 0 && " Size expected to be positive" );
1139
+
1140
+ if (LaterStart > EarlierStart &&
1141
+ // Note: "LaterStart - EarlierStart" is known to be positive due to
1142
+ // preceding check.
1143
+ (uint64_t )(LaterStart - EarlierStart) < EarlierSize &&
1144
+ // Note: "EarlierSize - (uint64_t)(LaterStart - EarlierStart)" is known to
1145
+ // be non negative due to preceding checks.
1146
+ LaterSize >= EarlierSize - (uint64_t )(LaterStart - EarlierStart)) {
1140
1147
if (tryToShorten (EarlierWrite, EarlierStart, EarlierSize, LaterStart,
1141
1148
LaterSize, true )) {
1142
1149
IntervalMap.erase (OII);
@@ -1148,16 +1155,23 @@ static bool tryToShortenEnd(Instruction *EarlierWrite,
1148
1155
1149
1156
static bool tryToShortenBegin (Instruction *EarlierWrite,
1150
1157
OverlapIntervalsTy &IntervalMap,
1151
- int64_t &EarlierStart, int64_t &EarlierSize) {
1158
+ int64_t &EarlierStart, uint64_t &EarlierSize) {
1152
1159
if (IntervalMap.empty () || !isShortenableAtTheBeginning (EarlierWrite))
1153
1160
return false ;
1154
1161
1155
1162
OverlapIntervalsTy::iterator OII = IntervalMap.begin ();
1156
1163
int64_t LaterStart = OII->second ;
1157
- int64_t LaterSize = OII->first - LaterStart;
1164
+ uint64_t LaterSize = OII->first - LaterStart;
1165
+
1166
+ assert (OII->first - LaterStart >= 0 && " Size expected to be positive" );
1158
1167
1159
- if (LaterStart <= EarlierStart && LaterStart + LaterSize > EarlierStart) {
1160
- assert (LaterStart + LaterSize < EarlierStart + EarlierSize &&
1168
+ if (LaterStart <= EarlierStart &&
1169
+ // Note: "EarlierStart - LaterStart" is known to be non negative due to
1170
+ // preceding check.
1171
+ LaterSize > (uint64_t )(EarlierStart - LaterStart)) {
1172
+ // Note: "LaterSize - (uint64_t)(EarlierStart - LaterStart)" is known to be
1173
+ // positive due to preceding checks.
1174
+ assert (LaterSize - (uint64_t )(EarlierStart - LaterStart) < EarlierSize &&
1161
1175
" Should have been handled as OW_Complete" );
1162
1176
if (tryToShorten (EarlierWrite, EarlierStart, EarlierSize, LaterStart,
1163
1177
LaterSize, false )) {
@@ -1179,7 +1193,7 @@ static bool removePartiallyOverlappedStores(const DataLayout &DL,
1179
1193
1180
1194
const Value *Ptr = Loc.Ptr ->stripPointerCasts ();
1181
1195
int64_t EarlierStart = 0 ;
1182
- int64_t EarlierSize = int64_t ( Loc.Size .getValue () );
1196
+ uint64_t EarlierSize = Loc.Size .getValue ();
1183
1197
GetPointerBaseWithConstantOffset (Ptr, EarlierStart, DL);
1184
1198
OverlapIntervalsTy &IntervalMap = OI.second ;
1185
1199
Changed |=
@@ -1428,8 +1442,8 @@ static bool eliminateDeadStores(BasicBlock &BB, AliasAnalysis *AA,
1428
1442
" when partial-overwrite "
1429
1443
" tracking is enabled" );
1430
1444
// The overwrite result is known, so these must be known, too.
1431
- int64_t EarlierSize = DepLoc.Size .getValue ();
1432
- int64_t LaterSize = Loc.Size .getValue ();
1445
+ uint64_t EarlierSize = DepLoc.Size .getValue ();
1446
+ uint64_t LaterSize = Loc.Size .getValue ();
1433
1447
bool IsOverwriteEnd = (OR == OW_End);
1434
1448
MadeChange |= tryToShorten (DepWrite, DepWriteOffset, EarlierSize,
1435
1449
InstWriteOffset, LaterSize, IsOverwriteEnd);
0 commit comments