Improve independence analysis in code optimizer #974

Merged
zxq9 merged 2 commits from fix_optimization_bug into master 2023-08-24 16:43:41 +09:00
Showing only changes of commit 17229f4014 - Show all commits

View File

@ -1141,11 +1141,16 @@ independent({i, _, I}, {i, _, J}) ->
StackI = lists:member(?a, [WI | RI]), StackI = lists:member(?a, [WI | RI]),
StackJ = lists:member(?a, [WJ | RJ]), StackJ = lists:member(?a, [WJ | RJ]),
if WI == pc; WJ == pc -> false; %% no jumps ReadStoreI = [] /= [ x || {store, _} <- RI ],
not (PureI or PureJ) -> false; %% at least one is pure ReadStoreJ = [] /= [ x || {store, _} <- RJ ],
StackI and StackJ -> false; %% cannot both use the stack
WI == WJ -> false; %% cannot write to the same register if WI == pc; WJ == pc -> false; %% no jumps
true -> not (PureI or PureJ) -> false; %% at least one is pure
StackI and StackJ -> false; %% cannot both use the stack
WI == WJ -> false; %% cannot write to the same register
ReadStoreI and not PureJ -> false; %% can't read store/state if other is impure
ReadStoreJ and not PureI -> false; %% can't read store/state if other is impure
true ->
%% and cannot write to each other's inputs %% and cannot write to each other's inputs
not lists:member(WI, RJ) andalso not lists:member(WI, RJ) andalso
not lists:member(WJ, RI) not lists:member(WJ, RI)