Skip to content

Commit 0104f37

Browse files
committed
[InstCombine] Use a cl::opt to control calls to getOrEnforceKnownAlignment in LoadInst and StoreInst
This is in preparation for the InferAlignment pass which handles inferring alignment for instructions separately. It is better to handle this as a separate pass as inferring alignment is quite costly, and InstCombine running multiple times in the pass pipeline makes it even more so. Differential Revision: https://reviews.llvm.org/D158527
1 parent 0f152a5 commit 0104f37

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ static cl::opt<unsigned> MaxCopiedFromConstantUsers(
3636
cl::desc("Maximum users to visit in copy from constant transform"),
3737
cl::Hidden);
3838

39+
extern cl::opt<bool> EnableInferAlignmentPass;
40+
3941
/// isOnlyCopiedFromConstantMemory - Recursively walk the uses of a (derived)
4042
/// pointer to an alloca. Ignore any reads of the pointer, return false if we
4143
/// see any stores or other unknown uses. If we see pointer arithmetic, keep
@@ -1048,11 +1050,13 @@ Instruction *InstCombinerImpl::visitLoadInst(LoadInst &LI) {
10481050
if (Instruction *Res = combineLoadToOperationType(*this, LI))
10491051
return Res;
10501052

1051-
// Attempt to improve the alignment.
1052-
Align KnownAlign = getOrEnforceKnownAlignment(
1053-
Op, DL.getPrefTypeAlign(LI.getType()), DL, &LI, &AC, &DT);
1054-
if (KnownAlign > LI.getAlign())
1055-
LI.setAlignment(KnownAlign);
1053+
if (!EnableInferAlignmentPass) {
1054+
// Attempt to improve the alignment.
1055+
Align KnownAlign = getOrEnforceKnownAlignment(
1056+
Op, DL.getPrefTypeAlign(LI.getType()), DL, &LI, &AC, &DT);
1057+
if (KnownAlign > LI.getAlign())
1058+
LI.setAlignment(KnownAlign);
1059+
}
10561060

10571061
// Replace GEP indices if possible.
10581062
if (Instruction *NewGEPI = replaceGEPIdxWithZero(*this, Op, LI))
@@ -1445,11 +1449,13 @@ Instruction *InstCombinerImpl::visitStoreInst(StoreInst &SI) {
14451449
if (combineStoreToValueType(*this, SI))
14461450
return eraseInstFromFunction(SI);
14471451

1448-
// Attempt to improve the alignment.
1449-
const Align KnownAlign = getOrEnforceKnownAlignment(
1450-
Ptr, DL.getPrefTypeAlign(Val->getType()), DL, &SI, &AC, &DT);
1451-
if (KnownAlign > SI.getAlign())
1452-
SI.setAlignment(KnownAlign);
1452+
if (!EnableInferAlignmentPass) {
1453+
// Attempt to improve the alignment.
1454+
const Align KnownAlign = getOrEnforceKnownAlignment(
1455+
Ptr, DL.getPrefTypeAlign(Val->getType()), DL, &SI, &AC, &DT);
1456+
if (KnownAlign > SI.getAlign())
1457+
SI.setAlignment(KnownAlign);
1458+
}
14531459

14541460
// Try to canonicalize the stored type.
14551461
if (unpackStoreToAggregate(*this, SI))

0 commit comments

Comments
 (0)