forked from jacobly0/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
missed optimizationMissed optimizations generate correct (no bugs) but not optimal codeMissed optimizations generate correct (no bugs) but not optimal code
Description
https://godbolt.org/z/bxT3aPjbd
The gmtime function always returns _gmtime.tm2 in HL. However, it seems that when localetime and gmtime are in the same translation unit, it decides to reload the value of _gmtime.tm2 into HL, even though HL will already always be set to that value.
struct tm *gmtime(const time_t *tp);
struct tm *localtime(const time_t *timer) {
time_t timer2 = *timer;
// subtracts zero since LOCALTIME_GMT_OFFSET is zero
timer2 -= LOCALTIME_GMT_OFFSET * SECS_PER_MIN;
return gmtime(&timer2);
}Same translation unit as gmtime:
BB0_27:
ld (_gmtime.tm2), bc
ld hl, _gmtime.tm2
ld sp, ix
pop ix
ret
public _localtime
_localtime:
ld hl, -4
call __frameset
ld iy, (ix + 6)
ld hl, (iy)
ld a, (iy + 3)
ld (ix - 4), hl
ld (ix - 1), a
pea ix - 4
call _gmtime
pop hl
ld hl, _gmtime.tm2
ld sp, ix
pop ix
retDifferent translation units:
_localtime:
ld hl, -4
call __frameset
ld iy, (ix + 6)
ld hl, (iy)
ld a, (iy + 3)
ld (ix - 4), hl
ld (ix - 1), a
pea ix - 4
call _gmtime
ld sp, ix
pop ix
ret
``Metadata
Metadata
Assignees
Labels
missed optimizationMissed optimizations generate correct (no bugs) but not optimal codeMissed optimizations generate correct (no bugs) but not optimal code