[Compiler] Preserve Currency scaling through Fastmath transforms

tests/webtbs/tw41865g and tw41865h, added by !1573 (merged), fail on current main f010f2a76c: both print raw=5, expected=50000 and exit 1.

Result := c / 2 inside a function returns a Currency value that has lost its scale. Under Fastmath (which -O4 enables) the division is turned into a multiplication by the reciprocal, and the two constant reassociations in taddnode.simplify move constants across the expression. Those transforms also fire when the subtree carries Currency scaling, and then the scaling operation is dropped or reordered.

This restricts the three transforms: the reciprocal conversion and both constant reassociations are skipped when the node, one of its two operands, or the constant that the reassociation would move carries nf_is_currency. In tw41865e/g at -O4 it is the * 10000 that typecheck_real_to_currency appends: its scaling constant carries the flag, and Fastmath reassociation folded it with the 0.5 from / 2, leaving a node marked as scaled without the factor.

(The first version searched the whole subtree; the follow-up commit replaced that with the check above, see the comment below.)

Measured on native aarch64-win64 (Snapdragon X Elite), two complete trees built from f010f2a76c differing only in this change, each installed and used with its own units:

test main f010f2a76c with this MR
tw41865g, tw41865h (-O4) exit 1, raw=5 exit 0
tw41865e, tw41865f (-O2) exit 0 exit 0
tw41865a, tw41865b, tw41865d exit 0 exit 0

Full make allexectests CPU_TARGET=aarch64 OS_TARGET=win64 in both trees, run one after the other: 3767 programs run in each; 49 failing tests on main, 46 with this MR, none new. The three that drop out are tw41865g, tw41865h and fcl-process/tests/testprocess - the last one is not this change: it passes 3 of 3 on both compilers when run alone.

tw41865c fails in both; that one is Currency div/mod and is handled in !1560. This MR adds no test of its own - !1573 (merged) already covers the case on all platforms.

The same patch was posted in !1557 (merged) (note 3806649609) on 2026-09-09 against that merge request's head; this is the same compiler change on current main.

Re-measured with the follow-up on main b2a65fd46f (2026-10-20, aarch64-win64): tw41865e/f at -O4 and tw41865g/h pass, as with the first version; a full make allexectests of the complete tree against the complete unmodified tree of the same revision differs only in tw41865g and tw41865h (3906 programs run, nothing new fails).

Edited by Sven Harazim

Merge request reports

Loading
Loading