qbe/test
Roland Paterson-Jones c2ff93e75e Global Value Numbering / Global Code Motion
More or less as proposed in its ninth iteration with the
addition of a gcmmove() functionality to restore coherent
local schedules.

Changes since RFC 8:

Features:

 - generalization of phi 1/0 detection
 - collapse linear jmp chains before GVN; simplifies if-graph
     detection used in 0/non-0 value inference and if-elim...
 - infer 0/non-0 values from dominating blk jnz; eliminates
     redundant cmp eq/ne 0 and associated jnz/blocks, for example
     redundant null pointer checks (hare codebase likes this)
 - remove (emergent) empty if-then-else graphlets between GVN and
     GCM; improves GCM instruction placement, particularly cmps.
 - merge %addr =l add %addr1, N sequences - reduces tmp count,
     register pressure.
 - squash consecutive associative ops with constant args, e.g.
     t1 = add t, N ... t2 = add t2, M -> t2 = add t, N+M

Bug Fixes:

 - remove "cmp eq/ne of non-identical RCon's " in copyref().
   RCon's are not guaranteed to be dedup'ed, and symbols can
   alias.

Codebase:

  - moved some stuff into cfg.c including blkmerge()
  - some refactoring in gvn.c
  - simplification of reassoc.c - always reassoc all cmp ops
      and Kl add %t, N. Better on coremark, smaller codebase.
  - minor simplification of movins() - use vins

Testing - standard QBE, cproc, hare, harec, coremark
          [still have Rust build issues with latest roland]

Benchmark
- coremark is ~15%+ faster than master
- hare "HARETEST_INCLUDE='slow' make check" ~8% faster
    (crypto::sha1::sha1_1gb is biggest obvious win - ~25% faster)

Changes since RFC 7:

Bug fixes:

- remove isbad4gcm() in GVN/GCM - it is unsound due to different state
    at GVN vs GCM time; replace with "reassociation" pass after GCM
- fix intra-blk use-before-def after GCM
- prevent GVN from deduping trapping instructions cos GCM will not
    move them
- remove cmp eq/ne identical arg copy detection for floating point, it
    is not valid for NaN
- fix cges/cged flagged as commutative in ops.h instead of cnes/cned
    respectively; just a typo

Minor features:

- copy detection handles cmp le/lt/ge/gt with identical args
- treat (integer) div/rem by non-zero constant as non-trapping
- eliminate add N/sub N pairs in copy detection
- maintain accurate tmp use in GVN; not strictly necessary but enables
    interim global state sanity checking
- "reassociation" of trivial constant offset load/store addresses, and
    cmp ops with point-of-use in pass after GCM
- normalise commutative op arg order - e.g. op con, tmp -> op tmp, con
    to simplify copy detection and GVN instruction dedup

Codebase:

- split out core copy detection and constant folding (back) out into
    copy.c, fold.c respectively; gvn.c was getting monolithic
- generic support for instruction moving in ins.c - used by GCM and
    reassoc
- new reassociation pass in reassoc.c
- other minor clean-up/refactor

Changes since RFC 6:

- More ext elimination in GVN by examination of def and use bit width
- elimination of redundant and mask by bit width examination
- Incorporation of Song's patch

Changes since RFC 5:

- avoidance of "bad" candidates for GVN/GCM - trivial address offset
    calculations, and comparisons
- more copy detection mostly around boolean values
- allow elimination of unused load, alloc, trapping instructions
- detection of trivial boolean v ? 1 : 0 phi patterns
- bug fix for (removal of) "chg" optimisation in ins recreation - it
    was missing removal of unused instructions in some cases

ifelim() between GVN and GCM; deeper nopunused()
2025-03-14 09:58:37 +01:00
..
_alt.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_bf99.ssa add big test file for qbe 2016-04-01 09:53:31 -04:00
_bfmandel.ssa add huge mandelbrot brainfuck example 2016-04-01 09:57:14 -04:00
_chacha20.ssa new chacha20 test 2021-10-28 15:53:51 +02:00
_dragon.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_fix1.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_fix2.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_fix3.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_fix4.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_gcm1.ssa Global Value Numbering / Global Code Motion 2025-03-14 09:58:37 +01:00
_gcm2.ssa Global Value Numbering / Global Code Motion 2025-03-14 09:58:37 +01:00
_live.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_load-elim.ssa Global Value Numbering / Global Code Motion 2025-03-14 09:58:37 +01:00
_rpo.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_slow.qbe make variadic args explicit 2021-10-22 23:53:25 +02:00
_spill1.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_spill2.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
_spill3.ssa extract tests out of src 2016-03-27 15:00:45 -04:00
abi1.ssa implement export control 2016-03-28 14:57:20 -04:00
abi2.ssa implement export control 2016-03-28 14:57:20 -04:00
abi3.ssa fix type bug in abi3 test 2016-04-12 11:33:32 -04:00
abi4.ssa make block labels per-function 2016-03-29 10:10:27 -04:00
abi5.ssa two new tests in abi5.ssa 2022-03-10 22:46:57 +01:00
abi6.ssa make variadic args explicit 2021-10-22 23:53:25 +02:00
abi7.ssa remove trailing whitespace from test/abi7.ssa 2021-10-26 21:26:10 +02:00
abi8.ssa handle large hfas correctly on arm64 2024-12-19 15:27:16 +01:00
alias1.ssa fix bug in alias analysis 2024-03-07 16:40:51 +01:00
align.ssa implement export control 2016-03-28 14:57:20 -04:00
cmp1.ssa amd64: fix conditional jump when compare is swapped and used elsewhere 2021-06-17 22:16:42 +02:00
collatz.ssa use a shift to divide by 2 in collatz 2016-04-12 14:51:50 -04:00
conaddr.ssa isel fix for amd64 memory stores 2019-04-30 11:21:45 +02:00
cprime.ssa implement export control 2016-03-28 14:57:20 -04:00
cup.ssa implement export control 2016-03-28 14:57:20 -04:00
dark.ssa new arm64_apple target 2022-10-03 10:41:26 +02:00
double.ssa implement export control 2016-03-28 14:57:20 -04:00
dynalloc.ssa fix dynamic stack allocs for amd64 2017-07-30 11:13:56 -04:00
echo.ssa make variadic args explicit 2021-10-22 23:53:25 +02:00
env.ssa amd64/sysv: unbreak env calls 2021-10-17 21:03:03 +02:00
eucl.ssa implement export control 2016-03-28 14:57:20 -04:00
euclc.ssa implement export control 2016-03-28 14:57:20 -04:00
fixarg.ssa add regression test for fixarg bug 2016-04-13 22:21:58 -04:00
fold1.ssa fix folding of unsigned operations 2019-04-29 12:01:54 +02:00
fpcnv.ssa test/fpcnv: skip of inexactly converted integers 2024-03-07 16:52:43 +01:00
gvn-live-dead.ssa Global Value Numbering / Global Code Motion 2025-03-14 09:58:37 +01:00
isel1.ssa fix amd64 addressing mode matcher 2019-02-21 14:46:18 +01:00
isel2.ssa test: add c[u]od checks to isel2 and add new integer compare test isel3 2022-02-17 22:35:22 +01:00
isel3.ssa test: add c[u]od checks to isel2 and add new integer compare test isel3 2022-02-17 22:35:22 +01:00
isel4.ssa fold scaled offsets in addresses 2024-04-11 14:14:53 +02:00
isel5.ssa fix various codegen bugs on arm64 2024-10-01 19:42:50 +02:00
ldbits.ssa new tests for the load optimization 2016-12-12 22:17:03 -05:00
ldhoist.ssa new tests for the load optimization 2016-12-12 22:17:03 -05:00
load1.ssa mark phi arguments as escaping 2019-02-18 13:56:03 +01:00
load2.ssa new blit instruction 2022-12-14 23:18:26 +01:00
load3.ssa bugfix in load elimination 2022-12-15 09:30:47 +01:00
loop.ssa implement export control 2016-03-28 14:57:20 -04:00
mandel.ssa implement export control 2016-03-28 14:57:20 -04:00
max.ssa implement export control 2016-03-28 14:57:20 -04:00
mem1.ssa new blit instruction 2022-12-14 23:18:26 +01:00
mem2.ssa kill dead stores when coalescing slots 2023-03-11 21:51:10 +01:00
mem3.ssa refresh stale Tmp.link before use 2023-03-13 10:51:41 +01:00
non0jnz.ssa Global Value Numbering / Global Code Motion 2025-03-14 09:58:37 +01:00
philv.ssa add regression test for liveon bug 2016-04-13 22:22:02 -04:00
prime.ssa implement export control 2016-03-28 14:57:20 -04:00
puts10.ssa implement export control 2016-03-28 14:57:20 -04:00
queen.ssa new eight queens test 2016-12-12 19:24:39 -05:00
rega1.ssa 2 bug fixes in rega 2019-02-06 09:02:25 +01:00
spill1.ssa emit valid code for mem->mem copies 2019-03-12 17:44:50 +01:00
strcmp.ssa add simple idiomatic c test 2017-02-23 11:37:26 -05:00
strspn.ssa add another idiomatic C test (rega does no good) 2017-03-03 10:52:09 -05:00
sum.ssa implement export control 2016-03-28 14:57:20 -04:00
tls.ssa tests for thread-local addresses 2023-04-02 18:54:26 +02:00
vararg1.ssa test: use architecture-neutral wrapper for calling vprintf 2021-09-07 08:31:48 +02:00
vararg2.ssa regenerate test/vararg2.ssa 2022-08-31 17:16:29 +02:00