Skip to content

Commit a87ff8d

Browse files
authored
[SROA] Remove sroa-strict-inbounds option (NFC) (#94342)
This option was added in 3b79b2a with the comment: > I had SROA implemented this way a long time ago and due to the > overwhelming bugs that surfaced, moved to a much more relaxed > variant. Richard Smith would like to understand the magnitude > of this problem and it seems fairly harmless to keep some > flag-controlled logic to get the extremely strict behavior here. > I'll remove it if it doesn't prove useful. As far as I know, it did not prove useful, so I'm removing it now. With constant GEPs canonicalized to i8, GEPs that only temporarily go out of bounds during the offset calculation do not naturally occur anymore anyway.
1 parent 79b1137 commit a87ff8d

File tree

1 file changed

+0
-43
lines changed

1 file changed

+0
-43
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ STATISTIC(
116116
STATISTIC(NumDeleted, "Number of instructions deleted");
117117
STATISTIC(NumVectorized, "Number of vectorized aggregates");
118118

119-
/// Hidden option to experiment with completely strict handling of inbounds
120-
/// GEPs.
121-
static cl::opt<bool> SROAStrictInbounds("sroa-strict-inbounds", cl::init(false),
122-
cl::Hidden);
123119
/// Disable running mem2reg during SROA in order to test or debug SROA.
124120
static cl::opt<bool> SROASkipMem2Reg("sroa-skip-mem2reg", cl::init(false),
125121
cl::Hidden);
@@ -1095,45 +1091,6 @@ class AllocaSlices::SliceBuilder : public PtrUseVisitor<SliceBuilder> {
10951091
if (GEPI.use_empty())
10961092
return markAsDead(GEPI);
10971093

1098-
if (SROAStrictInbounds && GEPI.isInBounds()) {
1099-
// FIXME: This is a manually un-factored variant of the basic code inside
1100-
// of GEPs with checking of the inbounds invariant specified in the
1101-
// langref in a very strict sense. If we ever want to enable
1102-
// SROAStrictInbounds, this code should be factored cleanly into
1103-
// PtrUseVisitor, but it is easier to experiment with SROAStrictInbounds
1104-
// by writing out the code here where we have the underlying allocation
1105-
// size readily available.
1106-
APInt GEPOffset = Offset;
1107-
const DataLayout &DL = GEPI.getModule()->getDataLayout();
1108-
for (gep_type_iterator GTI = gep_type_begin(GEPI),
1109-
GTE = gep_type_end(GEPI);
1110-
GTI != GTE; ++GTI) {
1111-
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand());
1112-
if (!OpC)
1113-
break;
1114-
1115-
// Handle a struct index, which adds its field offset to the pointer.
1116-
if (StructType *STy = GTI.getStructTypeOrNull()) {
1117-
unsigned ElementIdx = OpC->getZExtValue();
1118-
const StructLayout *SL = DL.getStructLayout(STy);
1119-
GEPOffset +=
1120-
APInt(Offset.getBitWidth(), SL->getElementOffset(ElementIdx));
1121-
} else {
1122-
// For array or vector indices, scale the index by the size of the
1123-
// type.
1124-
APInt Index = OpC->getValue().sextOrTrunc(Offset.getBitWidth());
1125-
GEPOffset += Index * APInt(Offset.getBitWidth(),
1126-
GTI.getSequentialElementStride(DL));
1127-
}
1128-
1129-
// If this index has computed an intermediate pointer which is not
1130-
// inbounds, then the result of the GEP is a poison value and we can
1131-
// delete it and all uses.
1132-
if (GEPOffset.ugt(AllocSize))
1133-
return markAsDead(GEPI);
1134-
}
1135-
}
1136-
11371094
return Base::visitGetElementPtrInst(GEPI);
11381095
}
11391096

0 commit comments

Comments
 (0)