From 0f9ac0f3788ece94bba8eb804cb5983b59d1380c Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Thu, 26 Aug 2010 21:30:49 +0100 Subject: [PATCH] Change optimiser policy, and fix optimiser bugs This includes a change in optimiser policy, such that optimising a run-time error into a compile-time error is considered a bug (which probably should have been the rule all along); the documentation was inconsistent on this before now. This is also needed for the testsuite to work with the optimiser. The specific bugs: constant folding could make a mingle guaranteed to overflow at runtime if the line was ever reached into a compile- time error; and folding an and into an or was occasionally an unchecked no-op, which causes the optimiser to enter an infinite loop (it's now checked that it's not a no-op in advance). --- doc/ick.txi | 6 ++---- src/idiotism.oil | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/ick.txi b/doc/ick.txi index a412094..f0361cf 100644 --- a/doc/ick.txi +++ b/doc/ick.txi @@ -6718,10 +6718,8 @@ particular @ical{} expression works. Make sure that the optimizer doesn't change a statement from a run-time error into something that silently succeeds@! Checking which bits can and can't be 1 is one good way to avoid this, especially with mingles. -(At present, there are some idioms that can turn run-time errors into -compile-time errors, such as with the expression -@code{''#65535$#65535'$#0'}; this could be avoided, but for the time -being it isn't.) +Likewise, don't optimise a run-time error into a compile-time error +(although creating a compile-time warning in this situation is fine). @item You can help@! If you find an idiom that the optimizer isn't optimizing diff --git a/src/idiotism.oil b/src/idiotism.oil index 5ab8997..c972259 100644 --- a/src/idiotism.oil +++ b/src/idiotism.oil @@ -34,7 +34,7 @@ ; Constant folding [minglefold] -(#{1}1$#{1}2)->(#{mingle(x1,x2)}0) +(#{x<=65535}1$#{x<=65535}2)->(#{mingle(x1,x2)}0) [selectfold] (#{1}1~#{1}2)->(#{iselect(x1,x2)}0) [and32fold] @@ -68,7 +68,7 @@ ; Reducing constants inside a C or operation can help to recognize idioms [cfoldintoorinand] -(((_1) | #{1}2) & #{1}3)->(((_1) | #{x2 & x3}0) & _3) +(((_1) | #{(x != x & x3)}2) & #{1}3)->(((_1) | #{x2 & x3}0) & _3) ; Binary bitwise optimizations [cbinand] -- 2.43.0