View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038053 | FPC | Compiler | public | 2020-11-08 23:10 | 2021-01-20 15:12 |
Reporter | Chris Rorden | Assigned To | J. Gareth Moreton | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | assigned | Resolution | open | ||
Platform | Apple Developer Transition Kit | OS | Darwin | ||
Product Version | 3.3.1 | ||||
Summary | 0038053: AArch64 -O2 bug not seen with -O1 | ||||
Description | Compiling the example software with -O2 reports a bogus value for variable fsz: fpc -O2 fsz.pas; ls -l dipso002.tif; ./fsz dipso002.tif But same code works when compiled as -O1. In this example, removing the unused variable "ok1" resolves the problem. Things seem to get confused when there are too many variables being juggled. | ||||
Steps To Reproduce | Incorrect file size reported when compiled with -O2: $fpc -O2 fsz.pas; ls -l dipso002.tif; ./fsz dipso002.tif Free Pascal Compiler version 3.3.1 [2020/11/07] for aarch64 Copyright (c) 1993-2020 by Florian Klaempfl and others Target OS: Darwin for AArch64 Compiling fsz.pas fsz.pas(80,11) Note: Local variable "ok1" not used Assembling fsz Linking fsz 264 lines compiled, 0.2 sec 1 note(s) issued -rw-r--r--@ 1 chris staff 1050090 Oct 4 2016 dipso002.tif >>> 1050090 Filesize 1050090 >>> 1050090 TIFF Filesize 248984 ReportTiff Error:IFDstart offset (1048584) exceeds filesize (248984) Correct file size reported when compiled with -O1: $fpc -O1 fsz.pas; ls -l dipso002.tif; ./fsz dipso002.tif Free Pascal Compiler version 3.3.1 [2020/11/07] for aarch64 Copyright (c) 1993-2020 by Florian Klaempfl and others Target OS: Darwin for AArch64 Compiling fsz.pas fsz.pas(80,11) Note: Local variable "ok1" not used Assembling fsz Linking fsz 264 lines compiled, 0.2 sec 1 note(s) issued -rw-r--r--@ 1 chris staff 1050090 Oct 4 2016 dipso002.tif >>> 1050090 Filesize 1050090 >>> 1050090 TIFF Filesize 1050090 ReportTiff: OK | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
FPCOldBugId | |||||
FPCTarget | |||||
Attached Files |
|
|
|
|
I failed to reproduce on linux64 with release and current trunk builds. Could you tell the exact svn version your're using? |
|
Jan Bruns: Issue is specific to AArch64 (ARM) CPUs. This does not impact x86-64 compiles. Tested with SVN is 47362 |
|
This one seems to be a bit more tricky. I can see the problem in the disassembly, although I'm not sure why the code is going bad. What I can tell is that it's writing an offset to a register that's in use (the same register that contains the actual correct size) and the bug seems to be in the node's second pass that coverts the tree into assembly language (I used DEBUG_NODE_XML to export the node trees, and there's nothing apparently wrong with it for fsz). |
|
It looks like there's more than one issue at play with this one - building the compiler with optimisations turned off causes the final binary to generate different code for fsz (in particular, AArch64's a_load_const_reg generates inefficient code when optimisations are turned on, but thankfully still produces correct constants) - however, the main bug of it overwriting a register that's in use is still present. Investigations continue. For clarity, with optimisations turned off when building the compiler, code for the constant "248984" is the following: movz x1,52376 movk x1,3,lsl 16 But under -O2, we get the following instead: movn x1,13159 movk x1,3,lsl 16 movk x1,0,lsl 32 movk x1,0,lsl 48 Somehow the condition controlled by "doInverted" gets flipped. |
Date Modified | Username | Field | Change |
---|---|---|---|
2020-11-08 23:10 | Chris Rorden | New Issue | |
2020-11-08 23:10 | Chris Rorden | File Added: aarch64.zip | |
2020-11-08 23:58 | J. Gareth Moreton | Assigned To | => J. Gareth Moreton |
2020-11-08 23:58 | J. Gareth Moreton | Status | new => assigned |
2020-11-10 16:42 | Jan Bruns | Note Added: 0126822 | |
2020-11-10 22:41 | Chris Rorden | Note Added: 0126828 | |
2020-11-25 20:50 | J. Gareth Moreton | Relationship added | related to 0038055 |
2020-11-28 16:00 | J. Gareth Moreton | Relationship added | related to 0038129 |
2021-01-20 06:35 | J. Gareth Moreton | Note Added: 0128443 | |
2021-01-20 15:11 | J. Gareth Moreton | Note Added: 0128450 | |
2021-01-20 15:12 | J. Gareth Moreton | Note Edited: 0128450 | View Revisions |