[sil-optimizer] Make compile time concatenation of constant strings work again

This guaranteed optimization got lost when a + operator for Strings was made a static method on type String.

Fixes SR-4348
This commit is contained in:
Roman Levenstein
2017-03-24 15:55:50 -07:00
parent b1efc95dab
commit 8082e820c9
2 changed files with 118 additions and 139 deletions

View File

@@ -687,9 +687,11 @@ bool StringConcatenationOptimizer::extractStringConcatOperands() {
if (!Fn)
return false;
if (AI->getNumOperands() != 3 || !Fn->hasSemanticsAttr("string.concat"))
if (AI->getNumArguments() != 3 || !Fn->hasSemanticsAttr("string.concat"))
return false;
assert(Fn->getRepresentation() == SILFunctionTypeRepresentation::Method);
// Left and right operands of a string concatenation operation.
AILeft = dyn_cast<ApplyInst>(AI->getOperand(1));
AIRight = dyn_cast<ApplyInst>(AI->getOperand(2));
@@ -730,6 +732,11 @@ bool StringConcatenationOptimizer::extractStringConcatOperands() {
AIRightOperandsNum == 5)))
return false;
assert(FRILeftFun->getRepresentation() ==
SILFunctionTypeRepresentation::Method);
assert(FRIRightFun->getRepresentation() ==
SILFunctionTypeRepresentation::Method);
SLILeft = dyn_cast<StringLiteralInst>(AILeft->getOperand(1));
SLIRight = dyn_cast<StringLiteralInst>(AIRight->getOperand(1));