CallishMachOp not constant folded
Summary
I found IDIV -1
instructions in NCG output of fannkuch-redux, i.e., integer division with remainder by -1.
The Cmm could have been constant folded (or even before that).
Steps to reproduce
Compiled in-tree nofib/fannkuch-redux with -O2
and dumped assembly. Found:
movq $-1,%rbx
movq %rax,160(%rsp)
movq %r14,%rax
movq %rdx,%r14
cqto
idivq %rbx
I.e., -1 is the divisor.
Corresponding Cmm is:
c665: // global
(_s5RR::I64, _s5RS::I64) = call MO_S_QuotRem W64(_s5R9::I64, (-1));
_s5Rg::I64 = _s5RS::I64;
_s5Rf::I64 = _s5RR::I64;
goto s5Re;
s5Re: // global
I8[_s5OS::I64 + _s5R8::I64] = %MO_UU_Conv_W64_W8(_s5Rf::I64);
(_s5Rp::I64) = call "ccall" arg hints: [PtrHint,
PtrHint,] result hints: [PtrHint] memcpy(_s5OT::I64, _s5OP::I64, _s5R8::I64 + 1);
_s5Ru::I64 = 0;
goto c65G;
Expected behavior
So, as far as I can tell, the remainder isn't even used and one could simply flip the sign of _s5R9.
Environment
- GHC version used: 9.0.1
Optional:
- Operating System: Ubuntu 20.04
- System Architecture: x86_64