AVR - Const value passed as parameter to procedure clobbered by peephole optimizer
Original Reporter info from Mantis: ccrause @ccrause
-
Reporter name: Christo Crause
Original Reporter info from Mantis: ccrause @ccrause
- Reporter name: Christo Crause
Description:
The test program (below in steps to reproduce) succeeds when compiled without optimization, but fails when compiled with optimization (-O1). The problem seems to be related to passing a constant as second parameter to procedure tests. When compiled without optimization registers r10..r17 are initialized correctly before calling procedure test (snippet #1 below). When compiled with -O1 registers r11 and r12 are eliminated by peephole optimization MovOp2Op.
It appears that the registers containing the constant value gets deallocated before the function call, hence the optimizer see the mov instructions as available for elimination.
Steps to reproduce:
program tshlshr;
procedure test(value, required: int64);
begin
if value <> required then
halt(1)
else
halt(0);
end;
var
longres : longint;
begin
longres := 32768;
test(longres, 32768);
end.
Additional information:
Snippet #1:
158: e1 2c mov r14, r1
15a: f1 2c mov r15, r1
15c: 01 2d mov r16, r1
15e: 11 2d mov r17, r1
160: a1 2c mov r10, r1
162: a0 e8 ldi r26, 0x80 ; 128
164: ba 2e mov r11, r26
166: c1 2c mov r12, r1
168: d1 2c mov r13, r1
16a: 0e 94 1d 00 call 0x3a ; 0x3a <PsTSHLSHR_ss_TESTsINT64sINT64>
Snippet #2:
14e: e1 2c mov r14, r1
150: f1 2c mov r15, r1
152: 01 2d mov r16, r1
154: 11 2d mov r17, r1
156: a1 2c mov r10, r1
158: a0 e8 ldi r26, 0x80 ; 128
15a: d1 2c mov r13, r1
15c: 0e 94 1d 00 call 0x3a ; 0x3a <PsTSHLSHR_ss_TESTsINT64sINT64>
Mantis conversion info:
- Mantis ID: 36079
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 43390 (#fabe4cc0)
- Monitored by: » dioannidis (Dimitrios Chr. Ioannidis)