Fix sign extension, again
In adc7f108 we fixed a number of issues
to do with sign extension in the AArch64 NCG found by ghc/test-primops>.
However, this patch made a critical error, assuming that getSomeReg
would allocate a fresh register for the result of its evaluation.
However, this is not the case as getSomeReg (CmmReg r) == r
.
Consequently, any mutation of the register returned by getSomeReg
may
have unwanted side-effects on other expressions also mentioning r
. In
the fix listed above, this manifested as the registers containing the
operands of binary arithmetic operations being incorrectly
sign-extended. This resulted in #22282 (closed).
Sadly, the rather simple structure of the tests generated
by test-primops
meant that this particular case was not exercised.
Even more surprisingly, none of our testsuite caught this case.
Here we fix this by ensuring that intermediate sign extension is performed in a fresh register.
Fixes #22282 (closed).