Skip to content

MUL & ADD aren't replaced by their constant counterparts in specific scenarios #2235

@Mark-Marks

Description

@Mark-Marks
local a = i * 1.27 -- MULK
local b = 1.27 * i -- MULK
local c = i + 1.27 -- ADDK
local d = 1.27 + i -- ADDK

for i = 1, 1_000_000 do
    local a = i * 1.27 -- MULK
    local b = 1.27 * i -- MUL
    local c = i + 1.27 -- ADDK
    local d = 1.27 + i -- ADD
end

Courtesy of @EternalAbby

Also seems to happen when i is a global, imported from another module (local i = require("...")), or the result of a table index (1.27 + foo.i). More perhaps to be tested

Note: O2

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions