unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#58905: Vector initialization loop remains even when allocation is elided
@ 2022-10-30 21:38 Ludovic Courtès
  0 siblings, 0 replies; only message in thread
From: Ludovic Courtès @ 2022-10-30 21:38 UTC (permalink / raw)
  To: 58905

Spot the issue in the code below?

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (version)
$28 = "3.0.8"
scheme@(guile-user)> ,c (let () (make-vector 12345 #\x) 42)
Disassembly of <unnamed function> at #xe8:

   0    (instrument-entry 42)                                 at (unknown file):5009:35
   2    (assert-nargs-ee/locals 1 1)    ;; 2 slots (0 args)
   3    (load-u64 1 0 12346)                                  at (unknown file):5009:11
   6    (load-u64 0 0 1)                
   9    (uadd/immediate 0 0 1)          
  10    (u64<? 0 1)                     
  11    (jnl 7)                         ;; -> L2
L1:
  12    (instrument-loop 30)            
  14    (handle-interrupts)             
  15    (uadd/immediate 0 0 1)          
  16    (u64<? 0 1)                     
  17    (jl -5)                         ;; -> L1
L2:
  18    (make-immediate 1 170)          ;; 42                 at (unknown file):5009:35
  19    (reset-frame 1)                 ;; 1 slot
  20    (handle-interrupts)             
  21    (return-values)                 

--8<---------------cut here---------------end--------------->8---

Vector allocation is elided (no ‘allocate-words’ instruction),
rightfully so (assuming we neglect the possibility of an out-of-memory
effect), but we still have the skeleton of the vector initialization
loop with its 12345 iterations.

Vector allocation is removed by the ‘eliminate-dead-code’ pass, which
happens on the VM instruction stream, so it explains why the loop
remains.

Still kinda surprising!

Also weird is the fact that ‘make-vector’ is kept by ‘peval’, on the
grounds that it might throw, but down the road it’s removed anyway.

Thoughts?

Ludo’.





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-30 21:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-30 21:38 bug#58905: Vector initialization loop remains even when allocation is elided Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).