Closed
Description
Bugzilla Link | 52481 |
Version | trunk |
OS | All |
CC | @topperc,@RKSimon,@phoebewang,@rotateright |
Extended Description
There seems to be an ordering issue in our handling of sdiv/srem by constant handling under -Oz.
These two test cases produce different code just from reordering the div and rem
int foo(int x, int *rem) {
*rem = x % 256;
return x / 256;
}
int bar(int x, int *div) {
*div = x / 256;
return x % 256;
}
foo: # @foo
mov ecx, 256
mov eax, edi
cdq
idiv ecx
mov ecx, eax
shl ecx, 8
sub edi, ecx
mov dword ptr [rsi], edi
ret
bar: # @bar
mov eax, edi
mov ecx, 256
cdq
idiv ecx
mov dword ptr [rsi], eax
mov eax, edx
ret
bar is using the remainder from the idiv, while foo is using the quotient to compute the remainder.