Ticket #1647 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

Constant folding on num type

Reported by: grom Owned by: plobsing
Priority: normal Milestone:
Component: imcc Version: 2.3.0
Severity: medium Keywords: constant folding
Cc: Language:
Patch status: Platform:

Description

grom@home$ cat t.pir 
.sub "main"
    .const num DAYS_PER_YEAR = 365.24 
    $N0 = 2.96460137564761618e-03 * DAYS_PER_YEAR 
    say $N0

    $N1 = DAYS_PER_YEAR * 2.96460137564761618e-03
    say $N1

    $N2 = 2.96460137564761618e-03
    say $N2

    $N3 = DAYS_PER_YEAR
    say $N3
.end

grom@home$ parrot t.pir 
0
0
0.00296460137564762
365.24

Attachments

t.pir Download (278 bytes) - added by grom 5 years ago.
Test case

Change History

Changed 5 years ago by grom

Test case

follow-up: ↓ 2   Changed 5 years ago by bacek

  • owner set to plobsing

Hello,

I do suspect that IMCC uses float instead of double for constant folding. There is 2 major problems:

0. Using float for constant folding is... weird.

1. IMCC without -On flag shouldn't optimize at all (apart from necessary constant folding for non-existent ops)

-- Bacek

in reply to: ↑ 1   Changed 5 years ago by plobsing

Replying to bacek:

I do suspect that IMCC uses float instead of double for constant folding. There is 2 major problems:

0. Using float for constant folding is... weird.

IMCC uses registers and invokes ops directly to fold. Whatever you use for FLOATVAL is what is used for folding.

1. IMCC without -On flag shouldn't optimize at all (apart from necessary constant folding for non-existent ops)

This is exactly what it is doing. mul_n_nc_nc does not exist. I'm fairly certain we don't have *any* ops with all constant arguments. This is likely a vestige from when our optimizer was held in high regard (btw, I recently ran -01 as a runcore test and it failed remarkably few tests).

What is going wrong is that DAY_PER_YEAR isn't being symbolic-constant-expanded before evaluation as a float (the string "DAYS_PER_YEAR" has a float value of 0). For reference, this works:

.sub "main"
  $N0 = 2.96460137564761618e-03 * 365.24
  say $N0
.end

  Changed 5 years ago by plobsing

  • status changed from new to closed
  • resolution set to fixed

fixed in r46906.

Note: See TracTickets for help on using tickets.