[Wasm] Optimize when using br_table only if all conditions read and compare the same variable
#KT-60212 Fixed
This commit is contained in:
committed by
Space Team
parent
39ef189e05
commit
5d1379ead1
+11
@@ -44,6 +44,17 @@ internal fun BodyGenerator.tryGenerateOptimisedWhen(expression: IrWhen, symbols:
|
||||
if (extractedBranches.isEmpty()) return false
|
||||
val subject = extractedBranches[0].conditions[0].condition.getValueArgument(0) ?: return false
|
||||
|
||||
// Do the optimization only if all conditions read and compare the same var or val
|
||||
// TODO: consider supporting other cases
|
||||
if (subject !is IrGetValue) return false
|
||||
val subjectValue = subject.symbol
|
||||
val allConditionsReadsSameValue = !extractedBranches.all { branch ->
|
||||
branch.conditions.all { whenCondition ->
|
||||
(whenCondition.condition.getValueArgument(0) as? IrGetValue)?.symbol == subjectValue
|
||||
}
|
||||
}
|
||||
if (allConditionsReadsSameValue) return false
|
||||
|
||||
// Check all kinds are the same
|
||||
for (branch in extractedBranches) {
|
||||
//TODO: Support all primitive types
|
||||
|
||||
Reference in New Issue
Block a user