If Expression optimization fails to preserve variable value
cardillan opened this issue · comments
Cardillan commented
The If Expression optimization may wrongly reuse a variable:
#set data-flow-optimization = off
i = rand(10)
i = i > 10 ? 1 : 2
print(i)
compiles to
op rand i 10 0
set i 2
jump 4 lessThanEq i 10
set i 1
print i
end
The optimizer moves the false branch in front of the if condition and replaces a temporary variable holding the result of the if expression with the eventual target -- i
, overwriting the value of i
before it is evaluated in the condition.