unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 58905@debbugs.gnu.org
Subject: bug#58905: Vector initialization loop remains even when allocation is elided
Date: Sun, 30 Oct 2022 22:38:51 +0100	[thread overview]
Message-ID: <87bkptyot0.fsf@inria.fr> (raw)

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’.





                 reply	other threads:[~2022-10-30 21:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bkptyot0.fsf@inria.fr \
    --to=ludo@gnu.org \
    --cc=58905@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).