Skip to content

[SILOpt][OSLog] Skip constant folding StaticString in the OSLogOptimization pass #79941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/SILOptimizer/Mandatory/OSLogOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,16 @@ static void substituteConstants(FoldState &foldState) {
for (SILValue constantSILValue : foldState.getConstantSILValues()) {
SymbolicValue constantSymbolicVal =
evaluator.lookupConstValue(constantSILValue).value();
CanType instType = constantSILValue->getType().getASTType();

// If the SymbolicValue is a string but the instruction that is folded is
// not String typed, we are tracking a StaticString which is represented as
// a raw pointer. Skip folding StaticString as they are already efficiently
// represented.
if (constantSymbolicVal.getKind() == SymbolicValue::String &&
!instType->isString())
continue;

// Make sure that the symbolic value tracked in the foldState is a constant.
// In the case of ArraySymbolicValue, the array storage could be a non-constant
// if some instruction in the array initialization sequence was not evaluated
Expand Down Expand Up @@ -976,7 +986,6 @@ static void substituteConstants(FoldState &foldState) {

SILBuilderWithScope builder(insertionPoint);
SILLocation loc = insertionPoint->getLoc();
CanType instType = constantSILValue->getType().getASTType();
SILValue foldedSILVal = emitCodeForSymbolicValue(
constantSymbolicVal, instType, builder, loc, foldState.stringInfo);

Expand Down