#dbugfix Issue 16189
ketmar
ketmar at ketmar.no-ip.org
Wed Feb 7 18:46:50 UTC 2018
Bastiaan Veelo wrote:
> On Wednesday, 7 February 2018 at 11:37:19 UTC, Michael wrote:
>> Does it work with slightly varied examples like where a = -1, and is
>> incremented etc.?
>
> I played with it here https://run.dlang.io/is/15sr6c and every variation
> I tried worked (correctly). So the example seems to be pretty minimal.
> Maybe someone understanding assembly is able to see what is going on
> after pressing that nice [ASM] button?
there is a mix of loop strength reduction and data flow analysis. as inner
loop contains array access and bounds checking, optimizer decided to turn
`a` into actual index (i.e. multiply it by 16), and use subtraction in loop body.
so far so good, optimizer did a good job. but then we have `assert(a ==
-1);` after the loop. and that is where things goes off the road: optimizer
knows that it has `a` in register, and it knows that `a` was pre-multiplied,
so it decided to divide `a` to 16 to get the real value. but... it does
this with `shr` instruction instead of `sar`! most of the time it works as
expected, but in our case... oops, we lost a sign.
the fix should be fairly easy, but sorry, i can't get any sense from dmd
backend. i see what it wrong due to my expirience with similar things, but
that's all. here Walter (or some other backand guru) should step in.
More information about the Digitalmars-d
mailing list